Reputation: 4096
what's wrong with my code, I don't get any values:
<script>
$(document).ready(function()
{
$("input[type=checkbox][checked]").each(function(event){
var get = $("input[@name=\'checkbox_pref\']:checked").val();
$("#result").html("&id=" + get);
});
});
</script>
</head>
<body>
<input type="checkbox" name="checkbox_pref" value = "1"/>
<input type="checkbox" name="checkbox_pref" value = "2"/>
<input type="checkbox" name="checkbox_pref" value = "3"/>
<div id="result">result ...</div>
Upvotes: 0
Views: 381
Reputation: 11855
Having just been checking a very similar type of functionality myself, here is my test. Just as a footnote FYI ;)
Upvotes: 0
Reputation: 21713
Depends what you're trying to do, but it should be more along the lines of:
$(document).ready(function()
{
$("input[type=checkbox]").change(function(event){
$("#result").html("&id=" + this.value);
});
});
Upvotes: 6
Reputation: 26190
You don't need to escape the single quotes or the @ symbol. Use this line:
$(document).ready(function()
{
$("input[type=checkbox][checked]").each(function(event){
var get = $("input[name='checkbox_pref']:checked").val();
$("#result").html("&id=" + get);
});
});
Upvotes: 2