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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change form action

Status
Not open for further replies.

travmak

Programmer
Apr 26, 2002
133
US
I am trying to make an onsubmit function that processes some form data, then depending on what submit button was clicked, submits the data to a different page.

is there anyway to do something like:

if (document.form.submit.value == 'Page One')
document.form.action = pageone.html
else
document.form.action = pagetwo.html

thanks for the help in advance.
 
A <form onSubmit=&quot;&quot;> can give you the ability for a handler and then use your function to choose your action or target based on conditions.
 
Depending on what you are basing it on

<form onSubmit=&quot;chooseValue()&quot;>

form.submitbutton1.onclick = function (){return true;}
form.submitbutton2.onclick = function (){return true;}


function chooseValue()
{if (&quot;submit button one&quot; = &quot;true&quot;)
{document.form.action = &quot;URL&quot;;}
else if(&quot;submit button 2&quot; = &quot;true&quot;)
{document.form.action = &quot;URL&quot;;}
}

Now, this may not be the most direct route. Hope it helps.
 
I'm basing the action on the submit button (I have 6)

what would the proper syntax be for the conditional?

here are my submit buttons.

<tr>
<td width=&quot;33%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit1&quot; style=&quot;visibility:visable&quot; value = &quot;Personal Information&quot;></td>
<td width=&quot;33%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit2&quot; style=&quot;visibility:visable&quot; value = &quot;Work Information&quot;></td>
<td width=&quot;34%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit3&quot; style=&quot;visibility:visable&quot; value = &quot;Team Work Codes&quot;></td>
</tr>
<tr>
<td width=&quot;33%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit4&quot; style=&quot;visibility:visable&quot; value = &quot;Government Information&quot;></td>
<td width=&quot;33%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit5&quot; style=&quot;visibility:visable&quot; value = &quot;Organization Information&quot;></td>
<td width=&quot;34%&quot; align=&quot;center&quot;><input type = &quot;submit&quot; name = &quot;submit6&quot; style=&quot;visibility:visable&quot; value = &quot;Point of Contact&quot;></td>
</tr>
 
how about
function goTo(value)
{if(value==0)
{document.form.action=&quot;URL1&quot;;}
else if(value==1)
{document.form.action=&quot;URL2&quot;;}
else if(value==2)
{document.form.action=&quot;URL3&quot;;}
else if(value==3)
{document.form.action=&quot;URL4&quot;;}
else if(value==4)
{document.form.action=&quot;URL5&quot;;}
}

<input type = &quot;submit&quot; name = &quot;submit4&quot; style=&quot;visibility:visable&quot; value = &quot;Government Information&quot;
onClick=&quot;goTo(0)>
<input type = &quot;submit&quot; name = &quot;submit5&quot; style=&quot;visibility:visable&quot; value = &quot;Organization Information&quot; onClick=&quot;goTo(1)>
etc...

I think that may be more of what you need. It doesn't sound like the most efficient way of doing things though with 6 submit buttons. What are you trying to do in the larger scheme?
 
I have an access databse that has to be webenabled (working for the government I can't just do it with access because not everyone has the same version so I have to start from scratch using ASP, JavaScript, HTML, and eventualy incorperate XML. The people I am creating this are very resistant to change, so the more like the original the better. The original had 6 &quot;tabs&quot; to navagate each section of the databse. The tables were setup by an extreme amature (table names were named stuff like &quot;tbl_julythegreat&quot; july being the name of the programmer, just to give you an Idea.) Rather that redo the whole thing with new naming conventions and create a bigger nitemare what I am going to try to do is this. Vice saving the information as they go (because they may not enter the correct information and as the database in access stands now there is no error checking) I am taking all of the 77 possble values and putting them in a hidden form. That way they can jump from page to page and keep all of the values. Once the visable form is filled out they have to save it manualy, like any other windows application. I think I have found an onBeforeUnload that will check to see if it has been saved before they try to leave. so this function would save the visable info into the hidden form, and then submit the hidden values to the page they want to go to. example:
the user starts on the personal information page. they fill it out, then click the &quot;work info&quot; button. The function copies the form values to the hidden form. Then changes the action to &quot;workinfo.asp&quot;. inside workinfo.asp the hidden form is populated again with the current hidden values (to be submitted to the next page they want to go to)
they fill out that page, the function copies the values from the form to the hidden form then changes the action to what ever page they then want to go to. by the time they get to the 3rd page they have the values from &quot;personal info, and &quot;work info&quot; tucked away in a hidden form waiting to be submitted to the 4th page or saved to the database.
Now i'm sure you're confused because I sure as heck am.
ultimatly I am trying to avoid using asp session variables to eliminate some problems and keep from using server memory to save 77 session state veriables (and using an array would just get confusing trying to keep them in order).
 
Travis? This is Virginia from the same job. LOL..yeah you have to love Julie's naming conventions. She was a little egocentric.
Did you get the last one to work? I am trying something similar for another function.
I am using layers in order to carry one set of variables to another page. I have to program for Netscape though because we have high security.
see ya later
:)
 
haha that's funny. Call me you know the number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top