Friday, February 12, 2010

Return false does not work with firefox?

Just cut and paste it in a notepad and save as a .html, then run it in IE and Firefox





When you feed less then 50 marks in the marks field, it will prompt you a javascript error alert in both the browsers, but in Firefox it will leave the marks field and will move to Submit button.





I want this to remain on the marks field as long as you dont feed a value more then 50





It works just fine in IE





Dont know what is it's problem with firefox. I have firefox version 2.0.0.14





==================================





%26lt;html%26gt;


%26lt;head%26gt;


%26lt;script type=';text/javascript';%26gt;


function check(){


if (document.f1.marks.value%26lt;50){


alert(';Minimum Marks should be %26gt;= 50';);


document.f1.marks.focus();


return false;


}


else return true;


}


%26lt;/script%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;form name=f1 method=post action=page2.php%26gt;


Name %26lt;input type=';text'; name=name%26gt;


Marks %26lt;input type=';text'; name=marks onblur=';return check();';%26gt;


%26lt;input type=submit name=add value=submit%26gt;


%26lt;/form%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;





================================Return false does not work with firefox?
You need to verify the %26gt;=50 before submitting the form as well as for onblur events on the value of the marks input. The blur won't be processed before the submit() is called on the form.





%26lt;html%26gt;


%26lt;head%26gt;


%26lt;!--


No matter which one you select,


pick a Best Answer.


--%26gt;


%26lt;script type=';text/javascript';%26gt;


function check(){


if (document.f1.marks.value %26lt; 50){


alert(';Minimum Marks should be %26gt;= 50';);


document.f1.marks.focus();


return false;


}


else return true;


}





function chkSubmit() {


if (!check()) return false;


document.f1.submit();


return true;


}





%26lt;/script%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;form name=';f1'; method=';post'; action=';page2.php';%26gt;


Name %26lt;input type=';text'; name=';name';%26gt;


Marks %26lt;input type=';text'; name=';marks'; onblur=';check();';%26gt;


%26lt;input type=';button'; value=';submit'; onclick=';chkSubmit()';%26gt;


%26lt;/form%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;Return false does not work with firefox?
Yes, the problem with your form is that it doesn't follow the best practice of quoting all values for attributes.





Also, you are using the reserved word ';name'; as the name of an input field, change it to ';name1'; or some other variation so it's not evaluated as a reserved word.
try placing the value of the name attribute of the input field of the form in double quotes

No comments:

Post a Comment