...

View Full Version : redirecting form submission with JS



maluch
08-08-2008, 06:58 AM
I need a javascript function to provide the value for the action field in a form.

my code is:



<form name='data' method='POST' target="_self" action= "javascript:return_direction()">

<input type='hidden' name='chk_status1'>
<input type='hidden' name='chk_status2'>
</form>


the JS function does return a string but the form is submitted to a blank website called javascript:return_direction() and then finally the string is returned. Can someone please help me? Thanks.

rangana
08-08-2008, 07:38 AM
Got your problem, but what should be the value of the action attribute? Could you please give a certain scenario about this.

And, out of curiosity, why would it be dependant on a hidden element?

maluch
08-08-2008, 07:47 AM
i am submitting data to different pages.
the problem is that depending on the user input the data has to be submitted to a different page. so i want to have this JS function analyze the input and then redirect the form to the proper page by returning the correct url, but until now i have not managed to do so. I know i could do it much easier in php, but due to php-JS communication and my lack of knowledge in that department this would be the easiest way if it could be made to work. thanks

maluch
08-08-2008, 07:50 AM
to clarify further i want the js function to return a value such as "test.php" and i want the html form to use "test.php" url of the website to submit data to instead of the apparent js function name. sorry to be so blunt, but i need this solution and fast. thanks for the help.

rangana
08-08-2008, 07:54 AM
Still vague. Could you please give an instance. For example a user types this value, and that value then the action should be this (something along this line instances).

abduraooft
08-08-2008, 08:02 AM
And what'd happen if there is no javascript support in browser?

maluch
08-08-2008, 08:02 AM
i'll try my best.

so the user inputs a bunch of data into a form. since this is a study, there is a specific sequence of check boxes that is correct. when the user is check boxes i am recording the times at which each check box was marked and storing these time values in js arrays. if the user presses submit with the wrong sequence of check boxes i tell him that he is wrong and reset them. if he, however, selects the right sequence i now need to send the arrays over to the next phase of testing. this next phase or a separate page is decided by the data that he or she has inputed. i have this function return_direction() analyze the form data and if teh correct sequence was submitted return the url of the proper next page to submit the js arrays to. now i need the html form to stop treating the jf function name as the address and use that what the function returns as the url to submit data to. thanks for reading.

maluch
08-08-2008, 08:03 AM
And what'd happen if there is no javascript support in browser?

well my target audience are college students that use facebook which requires js. so i think i'm fine, if not then they just cant participate in the study.

rangana
08-08-2008, 08:13 AM
I don't know what's with your return_direction() function, but this might keep you moving:


<script type="text/javascript">
window.onload=function(){
document.forms['data'].onsubmit=function(){
// if (something==anything)
// action here
this.action='http://www.google.com';
}}
</script>
<form name='data' method='POST' target="_self">

<input type='hidden' name='chk_status1'>
<input type='hidden' name='chk_status2'>
<input type="submit" value="test">
</form>

maluch
08-08-2008, 08:24 AM
Perfection!!! Thank you so much...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum