0

Ok I have four parameters in the url

xxx.html?p1=something&p2=else&p3=here&p4=too

And I have five different options for each p parameters. Now I'd need to change each parameter with on click event.

I can't use normal href since there are four different and independent variables. So I'd need jquery to search for right parameter and change it accordingly with on click

Thank you all!

1
  • Have you made any attempts at this? You might check out this jQuery-URL-Parser. Commented Nov 7, 2011 at 18:46

2 Answers 2

1

With this jQuery plugin you can do simply this:

window.location.search = jQuery.query.set("p2", "something");

I hope that this helps.

Sign up to request clarification or add additional context in comments.

5 Comments

Brilliant! Although now all the other stuff I'd like to achieve in the click function doesn't work since the page is reloaded
There is a solution, but for complete answer, please specify what are you goals, and put here complete code / example..
$("ul.p2 li").click(function() { var selected = $(this).text(); $("input#hidden2").val(selected); $(".info").html(selected); $(this).siblings().removeClass('selected'); $(this).addClass('selected').nextAll().addClass('selected'); window.location.search = jQuery.query.set("com", selected); }); This kinda thing
Ok, so let put this way: you want to rewrite the browser URL without refreshing? If you change only the hash, it won't reload the page - but if you change anything else in the URL, it WILL reload the page - what you obuisly don't want. So either you can use window.location.hash and change parameters without refresh or you can store all parameters as JavaScript variables, and after put them in URL string. For more information see this: stackoverflow.com/questions/1898331/… and related questions.
Since I only need to build these parameters for Facebook share button is there a way to query these for a certain var and then output to facebook share function? I mean the reload flickering is killing me...
0

First off, I suspect you want this to be a form and not a link, and have your attributes be hidden fields.

The implementation will require you to attach an event to the click event.

<a href="#" class="link" onclick="return false;">Click here</a>

$(".link").click(function(){
   p1_value = $(".p1_input").val(); // Or wherever the value is coming from...
   p2_value = $(".p2_input").val();
   url = "xxx.html?p1=" + p1_value + "&p2=" + p2_value;
   window.location = url;
})

You may want to use another library for building the URL, as there are a number of edge cases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.