Form submit with 2 selected values

Hello,

I need to submit a form with a url query like this ?car=black

What would be the jquery code?

Thanks

<select id="opt1">

   
    <option selected="selected">red</option>
    <option>black</option>
    
  </select>
  <select id="opt2">

    <option>car</option>
    <option selected="selected">bus</option>
    <option>train</option>
    
  </select>

You don’t need any JavaScript to accomplish this, the following would be sufficient to do the above.

<form action="" method="get">
    <select name="color">
        <option value="red">Red</option>
        <option value="black">Black</option>
    </select>
    
    <select name="type">
        <option value="car">Car</option>
        <option value="bus">Bus</option>
        <option value="train">Train</option>
    </select>
    
    <input type="submit" value="Submit" />
</form>

Hello, Thanks Chris. But query in your code is ?color=black&type=car because of your added select name attributes.

Actually I am working on WordPress custom post type where I need the exact query like this ?car=black or ?<2nd selected option>=<1st selected option> to retrieve data.

Thats why I need javascript/jquery.

If your form has a submit button with an id=“submit”…

$("#submit").click(function () { $("#opt1").attr("name", $("#opt2").attr("value")); });

Thanks bgil, I tried with attr before your post but could not make it but you did!.