Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2008, 06:58 AM   PM User | #1
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
redirecting form submission with JS

I need a javascript function to provide the value for the action field in a form.

my code is:

Code:
<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.
maluch is offline   Reply With Quote
Old 08-08-2008, 07:38 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
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?
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
maluch (08-08-2008)
Old 08-08-2008, 07:47 AM   PM User | #3
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
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 is offline   Reply With Quote
Old 08-08-2008, 07:50 AM   PM User | #4
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
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.
maluch is offline   Reply With Quote
Old 08-08-2008, 07:54 AM   PM User | #5
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
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).
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
maluch (08-08-2008)
Old 08-08-2008, 08:02 AM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
And what'd happen if there is no javascript support in browser?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 08-08-2008, 08:02 AM   PM User | #7
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
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 is offline   Reply With Quote
Old 08-08-2008, 08:03 AM   PM User | #8
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
Quote:
Originally Posted by abduraooft View Post
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.
maluch is offline   Reply With Quote
Old 08-08-2008, 08:13 AM   PM User | #9
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
I don't know what's with your return_direction() function, but this might keep you moving:
Code:
<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>
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
maluch (08-08-2008)
Old 08-08-2008, 08:24 AM   PM User | #10
maluch
New Coder

 
Join Date: Jul 2008
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
maluch is an unknown quantity at this point
Perfection!!! Thank you so much...
maluch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:58 PM.


Advertisement
Log in to turn off these ads.