0

so i have a form set up with multiples 'select' and options like so:

<form>

<select name="box1">
    <option value="1">1</option>
    <option value="2">2 </option>
    <option value="3">3</option>        
</select>

<select name="box2">
    <option value="a">a</option>
    <option value="b">b </option>
    <option value="c">c</option>        
</select>

<input type="submit">
</form>

and i want to retrive the link that would normally be made when you press the submit button but without refreshing the browser so i can let the users copy that link and send it to other people so they can see what options they picked.

i asume this would be possible in javascript but im not sure how and i couldent find any results on google.

Matt Cain
  • 5,638
  • 3
  • 36
  • 45
lizart
  • 127
  • 2
  • 2
  • 8
  • Is this question helpful to you? http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page – George Jul 17 '13 at 08:17
  • you can access a single form value via jquery `$('select[name=box1]').val();` http://api.jquery.com/val/ – steven Jul 17 '13 at 08:20
  • @F4r-20 its sort of usefull but it dosent actually explain how to retrive the link it creates when you press submit, atleast as far as i can tell – lizart Jul 17 '13 at 08:20

2 Answers2

2

I've created a fiddle here: http://jsfiddle.net/wgtVC/1

I'm using jQuery and the serialize() function for forms. This will create the querystring part of the url.

You can then use this to append to the URL where the form should post to.

Here is the code from the link above:

$('form').submit(function(){
    // get the serialized form
    alert($(this).serialize()); // "box1=1&box2=a"

    // append to a string which is the link the form posts to
    link = "http://link.to/my/website";
    alert(link+"?"+$(this).serialize()); // "http://link.to/my/website?box1=1&box2=a"

    return false;
});
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
0

In jQuery, there is the serialize function which allow you to do that. You can try this code if you want :

$('form').click(function() {
    parameter = $(this).serialize()
    alert(window.location.pathname + parameter)
})
Lucas Willems
  • 6,673
  • 4
  • 28
  • 45