Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing FORM fields to a Function 2

Status
Not open for further replies.

PaulSWT

Technical User
Jul 22, 2003
3
US
I have a FORM setup, that when the information is submitted I need all the fields to be passed to the function strfinderS(). Within the FORM tag I am using onSubmit to pass the fields into a function (VerifyStore) to check to see whether the form fields are valid.

This is where I become stuck. How can I then pass the fields again to the next function from within that function?

<script language=&quot;JavaScript&quot;>
<!--
function VerifyStore() {
if (document.srchStore.zpcd.value == &quot;&quot;) {
alert(&quot;Please enter your ZIP CODE.&quot;);
document.srchStore.zpcd.focus();
return false;
} else if (document.srchStore.rng.value == &quot;&quot;) {
alert(&quot;Please select the RANGE you would like to search within.&quot;);
document.srchStore.rng.focus();
return false;
} else
return true; // How can I pass the fields from this point to the next function strfinderS?
}
//-->
</script>

Any help is appreciated. I was able to setup the form using the <input type=button value=strfinderS(this.form)> but I have noticed when using the BUTTON type, the user cannot press enter to submit the form.
 

____________________________________________________
[sub]Python????? The other programming language you never thought of!
thread333-584700[/sub]
onpnt2.gif
 
PaulSWT,

Here are a couple ideas...althought I'm not quite sure what you're aiming for:

Something you might try doing (which is how I validate form input) is to make a custom button (b/c the default ones SUCK)...and use the onClick event to make a &quot;custom&quot; submitting function to submit the form once it's fields have been validated. For example:

------------------------------------------------------------
<img src=&quot;somesource.gif&quot; alt=&quot;submit&quot; onClick=&quot;submitForm()&quot;>

function submitForm(){
// here, simply check to see if the form input is valid; if so - then submit the form:
if( VerifyStore( ) && strfinderS( ) ){ // make sure that both VerifyStore( ) and strfinderS returns either true or false
document.form.submit(); // takes you to the script in the &quot;action&quot; attribute
}else{
alert(&quot;Form data is not vaid.&quot;);
// here you can put other options to help the users out...
}
}
------------------------------------------------------------

Of course, you can make this as fancy as you want - this is just an example.

I think it's much easier this way to validate form information. You always want to keep bad data from going to the server.

This might not have been what you're asking for, but it might put a different perspective on things.
 
Thanks, both posts were helpful. I got everything figured out now!
 
maybe post your solution for others searching the forum with the same question?

(you never know, they might!)


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top