View Full Version : How to hold page from unregresh.

imran khan
Feb 12th, 2011, 06:34 AM
i am calling a javascript function from my form on "onsubmit" it return false what i want, but the page is refresh again, which i am not want...

my code is:
<form id="form1" name="form1" method="post" action="" onsubmit="return validate_fields();">

function validate_fields(){
if(document.getElementById('name').value == ''.................){
return false;
return true;


Philip M
Feb 12th, 2011, 09:16 AM
Are you sure that you have the condition correctly expressed? As it is the form will return false only if name.value == "something", and if name is anything else it will return true and submit the form.

Put alerts in to test.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Feb 13th, 2011, 02:40 AM
Also, judging by that missing double quote in your example code, you could very well have an error somewhere, which will stop code execution, so the form will just be submitted without validation. Use a debugger to find out.