PDA

View Full Version : alert and submit problem


zuzupus
09-11-2003, 11:16 AM
hi,
i created 2 time drop downs and i prevent user to push Save button untill and unless he selects the time and mind there is images when user clicks it displays system time in drop down so now what happening when user try to push Save without selecting time he will get alert but when he selects ok it must return false but it submit the problem
<input type="submit" value="Save" name="Save" border="1" onclick="go();">
function go(){
var myindex=document.forms"tstest".to.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time from To drop-down menu is selected.");
}
else {
document.tstest.submit(); }
}//submit go()

but when i give type=button then it trurns false for alert but then it wont submit the form

i will go mad this really sucks

plz have a look at http://server2.vitodesign.com/scripts/test.phtml
u will see Von and Bis time drop downs and if u try to push sav u will get alert and it submitt he form it wont happen

u will get generated HTML file if still not clear plz let me know

thanks

Mr J
09-12-2003, 03:32 PM
You need to validate somehow


<SCRIPT>
<!--
function check(){
var correct = true

if (!correct){
correct = false
}

if (correct){
alert("ok")
}
return correct
}
//-->
</SCRIPT>

<form onsubmit="return check()">
</form>

Kor
09-12-2003, 04:44 PM
The key word, so to say, is return before a validation function, altogether insert in the form tag, on onsubmit event:


<form method="" action="" onSubmit="return validate()">


the validation function has to specify return true or false, acording to the conditions . It can be something like


function validate () {
if (condition here) {
alert ("You don't fulfill the condition!"); return false;
}
return true;
}


If you have some texarea input, as a bonus :-) you can insert a focus() comand, to focus the client's mouse on the wrong place


function validate () {
if (condition here) {
alert ("You don't fulfill the condition!"); document.form_name.element_name.focus(); return false;
}
return true;
}

zuzupus
09-15-2003, 08:48 AM
thanks Kor for ur awesome advice i really appreciated

regards