www.webdeveloper.com
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2006
    Posts
    4

    Question dropdown selection determines redirect page

    I would like to make a form with a drop down list.

    On selection of Item 1 from the menu I would like the page to direct to somepage1.html after the submit button is selected.

    On selection of Item 4 from the menu, I would like the page to direct to somepage4.html after the submit button is selected.

    On selection of any other item from the dropdown menu I would like the page to direct to somepage2.html after the submit button is selected.

    I'm a newbie at this and any help will be appreciated. Thank you very much!

  2. #2
    Join Date
    Jan 2006
    Location
    I'm in GMT -5
    Posts
    561
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    	function setAction(nPage){
    
    		document.forms[0].action = nPage;
    	}
    
    </script>
    </head>
    <body>
    
    <form>
    <select onchange="setAction(this.value)">
    <option value=''> Make a selection </option>
    <option value='somepage1.html'> Option 1 </option>
    <option value='somepage2.html'> Option 2 </option>
    <option value='somepage2.html'> Option 3 </option>
    <option value='somepage4.html'> Option 4 </option>
    </select>
    &nbsp;&nbsp
    <input type='submit' value="Submit">
    </form>
    
    </body>
    </html>

  3. #3
    Join Date
    Apr 2006
    Posts
    4
    Thank you very much for your generous reply James.
    I tried your code and it works great. However, I need to get this to work within an .asp mailing redirect program... so that all the data from the form is sent to an email address and the user, gets redirected to another page after hitting submit.

    I finally found a previous post that sums up more distinctly what I need. I'm apologize for this extra post and will try to do better in the future to do a more thorough search before posting a new topic. mea culpa

    If anyone can help out with the issue it is summed up better here I think.

    http://www.webdeveloper.com/forum/sh...ad.php?t=21221

    Many thanks!

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    Simple enough -- if the server-side page is not returning any results to the client. If it is, then you're pretty much outta luck. The solution is to use the FORM's onsubmit event to schedule (window.setTimeout) a JavaScript redirect (window.location.href='url') which then takes place *after* the FORM has been submitted to the server.

  5. #5
    Join Date
    Jan 2006
    Location
    I'm in GMT -5
    Posts
    561
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    	function validate(nForm){
    
    		if (nForm['redirectPage'].value == "")
    			{
    			 alert('Choose from the list');
    			 return false;
    			}
    		alert(nForm['mail_redirect'].value)
    	}	
    
    </script>
    </head>
    <body>
    
    
    <form action="formmail.asp" method="post" name="form1" onsubmit="return validate(this)">
    <input id="mail_to" type="hidden" name="mail_to" value="myemail@domain.com" /> 
    <input id="mail_redirect" type="hidden" name="mail_redirect" value="submititem1.htm" />
    <input id="mail_send" type="hidden" name="mail_send" value="y" />
    <br><br>
    <select name='redirectPage' onchange="this.form['mail_redirect'].value=this.value">
    <option value=''> Make a selection </option>
    <option value='somepage1.html'> Option 1 </option>
    <option value='somepage2.html'> Option 2 </option>
    <option value='somepage2.html'> Option 3 </option>
    <option value='somepage4.html'> Option 4 </option>
    </select>
    &nbsp;&nbsp
    <input type='submit' value="Submit">
    </form>
    
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

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



Recent Articles