I do not understand why it still does not pass the form, even if I choose another checkbox? According to the if-else action, if else is empty, then do it
HTML:
<form action="http://youtube.com" method="get">
<ul>
<li>
<input id="checkbox_yoda" type="checkbox" name="character" value="light_side">
<label for="checkbox_yoda" data-sentence="Force is strong in you">Yoda</label>
</li>
<li>
<input id="checkbox_trooper" type="checkbox" name="character" value="dark_side">
<label for="checkbox_trooper" data-sentence="Just chillin'">Trooper</label>
</li>
<li>
<input id="checkbox_vader" type="checkbox" name="character" value="dark_side">
<label for="checkbox_vader" data-sentence="There is no escape from the Dark Side.">Vader</label>
</li>
</ul>
<button type="submit">Turn to the dark side</button>
</form>
JQUERY:
$("document").ready (
function()
{
$("button").click(
function()
{
if ($("input#checkbox_yoda :selected"))
{
alert('you pick yoda');
return false;
}
else
{
return true;
}
}
)
}
)
$()returns a jQuery object. And objects in javascript are truthy. If you put.lengthon the end of it, it will return 0 if the element is not found, and 0 is falsey$('#checkbox_yoda').is(':checked')- if it is a checkbox -:selectedis for dropdownlists