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!

Understanding how the submit form botton works

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
US
I have a form with 3 select boxes that allow you to select the state / metro area / city. The select boxes refresh the page with OnChange each time a selection occurs - all is working well.

What i want to happen when the user clicks on the submit button is to send the user to the action page.

Code:
<form method="post" action="actionPage">

I have created a condition with Coldfusion to not have the action statement in the form tag until all 3 select boxes have values. And this works fine.

The problem comes when the user has made all his selections and then reselects a different state then all of sudden the onChange event sends them to the action page. I don't want this to happen - I only want to send them to the action page ONLY when they have pressed the Submit button.

What i am asking is a way to write my code this way:

Code:
<If user makes selections from the select box - just refresh the page> (I have this part working)

<If the user has made selections to the select boxes (I have this validation working fine) AND presses the Submit button - then place action="actionPage" in to the form tag>

 
Wherever the line of code that submits the form when you change the selection of a dropdown list exists, right before it, put:

document.forms[0].action = "";

There's probably a better way to do what you're doing (especially if you can count on users having JavaScript enabled), but I believe the above is the answer to the specific question you've asked.

'hope that helps.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Dave,

Thanks, i will try that tonight.

I know there are many other ways to do what i am doing with the multiple select boxes, but this was the easy for me to understand.

Thanks!
 
Dave,

This is the code I have now that submits the form when you change the selection of a dropdown list (for states):

Code:
<select name="state" onchange="this.form.submit();" required="yes">

So what you recommend is doing this?

Code:
<select name="state" document.forms[0].action = "myAction.cfm"; onchange="this.form.submit();" required="yes">

So by adding this, when the user clicks on the submit button (and all is valid) it will send them and their form variables to myAction.cfm page?

I am guessing that the action element in the form tag gets deleted:

Code:
<form method="post" action="actionPage">

to:

<form>
 
Never mind, i figured it out.

I used the "location.url =" javascript command to steer it to the right page when i had it all validated.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top