Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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

  • Users who have thanked rangana for this post:

    maluch (08-08-2008)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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

  • Users who have thanked rangana for this post:

    maluch (08-08-2008)

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    And what'd happen if there is no javascript support in browser?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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

  • Users who have thanked rangana for this post:

    maluch (08-08-2008)

  • #10
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Perfection!!! Thank you so much...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •