Hi..guys!I have a drop down menu with javascript null validation.However,instead of clicking submit button,it will immediately auto redirect after option was selected.Is it possible to prevent this kind of fast respond?
Code:<select name="rNumber" title="number of ticket" onChange="GoToNextPage(this.value)"> <option selected>Select</option> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> </select>Code:<script language="JavaScript" type="text/JavaScript"> function validate(which) { var selects = which.getElementsByTagName('select'); var radios = which.getElementsByTagName('input'); for(sel = 0; sel < selects.length; sel++) { if(selects[sel].options[selects[sel].selectedIndex].text == 'Select') { alert('Please select number of ticket!'); return false; } } var rselCount = 0; for(radio = 0; radio < radios.length; radio++) { if(radios[radio].checked) { rselCount++; } } if(rselCount == 0) { alert('Please select screening time!'); return false; } return true; } function GoToNextPage(value){ if(value != ""){ document.location = 'reservation3.php?selected_no_ticket=' + value; } }And also when onchange mixed with onsubmit,the validation can't executeCode:<form action="reservation3.php" method="post" name="movieList" onSubmit="return validate(this);">
alert('Please select screening time!'); when radio button was not selected.What went wrong in the script?Thanks...



Reply With Quote

Bookmarks