Trying to prevent submit until one radio button is selected using jquery -


must syntax error, because can't first alert

my submit button:

input type="submit" name="payonline" id="payonline" value="pay online" style="color: red; font-    weight: bold; width:100px; height:40px;"/>  

jquery:

<script> $("#payonline").click(function() {  alert("submit button clicked on"); if ($("input:radio[name='epackage']:checked").val() <0 ) {    alert('nothing checked!');     return false;    event.preventdefault();  }  else {   alert('one of radio buttons checked!'); } }); </script> 

you want change .val .length. return value of 0 or 1. change if '<= 0'...

<form>     <input type="radio" name="epackage" value="1">option 1<br>     <input type="radio" name="epackage" value="2">option 2     <input type="submit" name="payonline" id="payonline" value="pay online" style="color: red; font-weight: bold; width:100px; height:40px;"/>      </form>  $("#payonline").submit(function() { alert("submit button clicked on"); if ($("input:radio[name='epackage']:checked").length <=0 ) {    alert('nothing checked!');    return false;  } else {   alert('one of radio buttons checked!'); }  }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -