Click to See Complete Forum and Search --> : Form Validation and submission


s_allamneni
08-19-2003, 04:53 PM
HI,
I have a form and when i click on the submit button it should check the validity of the values entered in the form and either one of the following should happen
1) if the validation fails i want to show an warning/error message and do nothing more
2) If forms contains all valid data i want to invoke an xyz.asp program with out refreshing the current page and also want to pop up status window.
Does any one know how to do this using java script.
Here is the sample code(which is not working properly):

<form action="xyz.asp" id=""frm1"" method="POST" name="frm1" target="nextpage">
<input maxLength="5" name="fquantity" size=5 value="2">
<input type="submit" value="Submit" name="click here" onClick="return validateForm(this);">
</form>
function validateForm(form)

var quant = form.fquantity.value
if ( (isNaN(quant) == true || quant < 1 || quant > 10000))
alert("Please enter the quantity");
form.fquantity.focus();
return false;
}
else
{
window.open("xyz.asp", "nextpage", "height=220,width=350,resizable=no,location=no...");
return true;
}

}
I appreciate any help...
Thanks,

Khalid Ali
08-19-2003, 07:08 PM
if your concern is only to invoke the *.asp page then you only need to do this
instead of this
window.open("xyz.asp", "nextpage", "height=220,width=350,resizable=no,location=no...");
return true;


window.open("xyz.asp", "nextpage", "height=220,width=350,resizable=no,location=no...");
return false;

thios will do that..however if you want to pass the form data to asp page then there is not way to not refresh the form page..because it has tosend the data to asp and then recieve back.

Scriptage
08-19-2003, 07:51 PM
You can dynamically create a new child element with the src as xyz.asp, this would pass data to the asp page. I think it was Vladdy (not sure) who wrote an excellent tutorial on how to do this. search for him and look back at his posts.
Regards

Vladdy
08-21-2003, 10:48 AM
Originally posted by Scriptage
... I think it was Vladdy (not sure)...
Guilty as charged;)
Here is the link: http://forums.webdeveloper.com/showthread.php?s=&threadid=5810

Be advised that this method works only in browsers which allow dynamic creation of script node. Gecko and IE5+ have tested positive, Opera - negative, don't know about the others.
Also, since the data is passed to the server in the form of query string so the amount is limited to ~2K depending on the type of proxies you have in-beween (when I tried to go the straight to my local host I was able to "transmit" 96K :D :D ). It should be enough for "database browsing" type applications but may be a problem if your form contains decent chunk of data

s_allamneni
08-21-2003, 12:42 PM
Thank you all,
i got it working...