I’m trying to alert some stuffs when a radio button is checked but my code isn’t working. Does anyone have any idea why?
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("input[@name='crkbrd']").change(function(){
if ($("input[@name='crkbrd']:checked").val() == 'Upload')
{ alert("Upload Your Own Ad"); }
else if ($("input[@name='crkbrd']:checked").val() == 'Edit')
{ alert("Edit Your Ad Here"); }
else
{ alert("You haven't chosen anything"); }
});
});
</script>
</head>
<body>
<input type="radio" id="rb1" name="crkbrd" value="Upload" /> Upload Your Own Ad<br />
<input type="radio" id="rb2" name="crkbrd" value="Edit" /> Edit Your Ad Here
</body>
</html>
Remove the
@in the name selectors. JQuery uses CSS selectors, which is in this format:•
elementselector[attribute=value]Use one of the following selectors instead:
You should have got this error message when you ran your code: