Form submission checkscript() javascript -
i want able submit form if 'my val 2' option selected. if option selected , submit button pressed, want cannot submit it. also, if submit it, want go submission page says submitted. here form:
<form action="formsub.php" method="post" name="myform" onsubmit="return checkscript()"> <select name="test_select"> <option value="1">my val 1</option> <option value="2">my val 2</option> <option value="3">my val 3</option> <option value="4">my val 4</option> </select> <input type="submit" value="submit" name="test_button" onclick="submitform(test_select.value)"> </form>
here javascript functions
function submitform(val) { var obj = val;; alert("value = " + obj); } function checkscript() { if (obj !== "2") { alert('this not \'my val 2\' cannot submit'); return false; } return true; }
also, checkscript function doesn't work correctly. f statement false.
you have mistake in script. javascript not see variable obj in scope of function checkscript(). rather try declare variable global variable. have examples how validate forms here: http://www.w3schools.com/js/js_form_validation.asp , : javascript form validation onsubmit @noob unchained write must value field script. have function submitform(val)
as see function gets value select panel. can try use function return selected value list.
var obj; function submitform(val) { obj = val; alert("value = " + obj); } function checkscript() { if (obj !== "2") { alert('this not \'my val 2\' cannot submit'); return false; } return true; }
for first function submitform()
set variable obj , second function use set obj check value.
but if use method @noob unchained because it's simpler , can validate many forms in 1 function. try read javascripts tutorials write scipts.
i hope you.
Comments
Post a Comment