I have a form, an input and a link. If the input has no value, clicking the link would direct to a certain url. If the input is NOT empty, then the click would have to submit the form. This is how the link looks like:
<li class="youtube"><a href="#">YouTube</a></li>
This is what I have so far in Jquery:
$('.youtube').bind('click', function() {
if($(input).val() == ''){
$(".youtube a").attr("href", "http://www.youtube.com/")
}else{
$(form).attr("action","http://www.youtube.com/results?search_query=");
$(form).submit();
}
});
This doesn’t work, I can’t figure out why.
You want to be targetting the link rather than the li
I.E.
$('.youtube a').bind('click')etc..Also have you got multiple input fields? Your input field needs to be in quotes otherwise you’re targetting a variable, i.e. ‘input’
To check for an empty string i’d just do:
So your full code would be: