javascript - disabling submit button till input fields are validated -
i have disabled submit button in guestbook. has 2 fields[name(textbox)&comment(textarea)].it has 2 other fields id(primary key) , date.the function is:
function frmvalidate() { var nmchk=document.forms["guestform1"]["name"].value; var cmntchk=document.forms["guestform1"]["comment"].value; if (nmchk.length==0) { var namep = document.getelementbyid("namep"); namep.innerhtml="name must filled out"; return false; } else if (cmntchk.length==0) { var cmntp = document.getelementbyid("cmntp"); cmntp.innerhtml="comment must filled out"; return false; } else { document.getelementbyid("sbmt").disabled=false; return true; } }
i have called function in places: body tag's onload,button tag's onclick. still not working , blank entries being stored in database.
you dont need disable submit button
you gain noting it. ( alerting user , running script etc...)
instead -- submit button should stop regular behaviour code :
<input type="submit" onclick="return frmvalidate();"/>
meaning :
when press button , execute function yielding true or false , if it's true (only) continue server.
Comments
Post a Comment