javascript - Field cannot be NULL -
how write code that,strictly must have value else "pay now" button not proceed.
for example fields
- card type 1 value must @ selected 1
- and enter card number must have value
- and enter pin must have value
else "pay now" button display "please make sure details have been filled.
the html
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>terms & conditions</title> <link rel="stylesheet" type="text/css" href="css/format.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css"> <script src="js/jquery-1.10.2.min.js"></script> <script src ="js/jquery-1.11.0.min.js"></script> <script src="js/jquery.cycle.all.js"></script> <style type="text/css"> </style> </head> <body background="images/wallpaper.jpg"> <h22><h1> <h> purchase </h> </h1></h22> <p> </p> <p> </p> <hr></hr> <p> </p> <h22><h1><p1><fieldset> <form action = ""> <p> <span> payment gateway </span> <br /><br /> <form> card type: <select> <option value="" style="display:none">select</option> <option value="one">master card</option> <option value="two">visa card</option> </select> <p> </p> enter card no:<input type="text" name="cardno" placeholder="0000-0000-0000"><br> <p> </p> enter pin no:<input type="text" name="pinno" placeholder="000"> <p><sil>(your 3-digit pin can found @ of card)</sil></p> <p> </p> <input type="submit" value="pay now" onclick="alert('thank you,your order processed shortly.stay tune..');"> </form> <br /> <br /></p> </form> </fieldset></p1></h1></h22> <p> </p> <p> </p> <p> </p> <p> </p> </body> </html>
you can check value of fields in function call onclick of submit button of form. below function same :
function validate() { var cardtype = $("#cardtype"); var cardno = $("#cardno"); var pinno = $("#pinno"); if(cardtype[0].selectedindex == 0 ){ alert('please select card type'); return false; } if(cardno.val() == '') { alert('please enter card number'); return false; } if(pinno.val() == '') { alert('please enter pin number'); return false; } alert('thank you,your order processed shortly.stay tune..'); return true; }
i have given id fields. change selector per requirement.
may validate form fields.
Comments
Post a Comment