SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast steveorg's Avatar
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query string in a form action

    I have a form issue. I hope that the JavaScript forum is the appropriate place for the question.

    The form has a select field that results in the user being forwarded to a URL. Here's the code:
    Code:
    <form action="http://somedomain.com?id1=test&amp;">
    <select name="type" onchange="this.form.submit()">
    <option value="FirstChoice">Choice 1</option>
    <option value="SecondChoice">Choice 2</option>
    <option value="ThirdChoice">Choice 3</option>
    </select></form>
    I'm expecting the result to look like this:
    http://somedomain.com?id1=test&type=FirstChoice

    However the result is this:
    http://somedomain.com?type=FirstChoice

    Does anyone know how I can get the desired result? Thanks.

    Steve

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    give this a try

    Code:
    <form action="http://somedomain.com?id1=test;" method="post">
    <select name="type" onchange="SubmitForm(this)">
    <option value="FirstChoice">Choice 1</option>
    <option value="SecondChoice">Choice 2</option>
    <option value="ThirdChoice">Choice 3</option>
    </select></form>
    <script type="text/javascript">
    	function SubmitForm(select) {
    		var form = select.form;
    		var action = form.action;
    		var choice = select.options[select.selectedIndex].value;
    		action += "&type=" + choice;
    		form.action = action;
    		form.submit();
    	}
    </script>

  3. #3
    SitePoint Enthusiast steveorg's Avatar
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Justin - magnificent! Thanks.


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
  •