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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Changing form action

    Hi,

    I searched the forums and found a few people asking this but i didn't understand any responses.

    I have a simple form with a drop down

    PHP Code:
    <form name="test" action="">
    <
    select name="change">
    <
    option value="page1.htm">page1</option>
    <
    option value="page2.htm">page2</option>
    <
    option value="page3.htm">page3</option>
    </
    select>

    <
    input name="submit" type="submit" value="submit"  />
    </
    form
    I'd like the form action to change depending on the option selected.

    If page 1 is selected then the form action would be 'page1.htm'

    If page 2 is selected then the form action would be 'page2.htm' and so on.

    Can someone please help me by explaining how i'd do this.

    Thanks in advance.

  • #2
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Do you want other data to submit to that page or just open that page?
    My Website: DumpsterDoggy

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try this version:
    Code:
    <html>
    <head>
    <title>Remote Control</title>
    </head>
    <body bgcolor="#FFFFFF">
    <form name="combo">
      <p><select name="go" size="1" onChange="window.location=this.options[this.selectedIndex].value">
           <option value=" " Selected>Select One</option>
           <option value="http://www.javascriptkit.com">Web Building Tutorials</option>
           <option value="http://www.mvsforums.com">MVS Help</option>
          </select> 
      </p>
    </form>
    </body>
    </html>

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PremiumBlend View Post
    Do you want other data to submit to that page or just open that page?


    Hi there,

    i just want to open that page that's all.

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jryoung View Post
    Try this version:
    Code:
    <html>
    <head>
    <title>Remote Control</title>
    </head>
    <body bgcolor="#FFFFFF">
    <form name="combo">
      <p><select name="go" size="1" onChange="window.location=this.options[this.selectedIndex].value">
           <option value=" " Selected>Select One</option>
           <option value="http://www.javascriptkit.com">Web Building Tutorials</option>
           <option value="http://www.mvsforums.com">MVS Help</option>
          </select> 
      </p>
    </form>
    </body>
    </html>
    i'll try that, thanks.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,456
    Thanks
    0
    Thanked 632 Times in 622 Posts
    If you want it to work with JavaScript disabled then you need to use a server side script to do the redirect to the selected page. The form needs to have the action set to that server side script. That then doesn't get called if the JavaScript code redirects to the selected page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New Coder
    Join Date
    Apr 2006
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    If you want it to work with JavaScript disabled then you need to use a server side script to do the redirect to the selected page. The form needs to have the action set to that server side script. That then doesn't get called if the JavaScript code redirects to the selected page.
    Server side sounds like it would be better, but again i have no idea how to go about it.

    I'm willing to try whatever's most effective - if you can help?


  •  

    Posting Permissions

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