0

I have 5 HTML buttons on a page. I want to pass the value of the particular button that has been clicked through a query string on second page through JavaScript. Please advise me.

3 Answers 3

2

I'm cheating and using jQuery, just to illustrate the concept.

You have your 5 buttons with their own unique IDs and all of them have a class of "button"

On clicking any of them, the browser will navigate to "http://mydomain.com/nextpage" with the "buttonclicked" parameter in the query string set to the ID of the button that was clicked.

$('.button').click(function(){
  window.location.href = "http://mydomain.com/nextpage?buttonclicked="+this.id;
});

Interactive example: http://jsfiddle.net/6EZvG/

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

2 Comments

If it has to be done with JavaScript, this seems like it would be the best idea -- though I think I would use the data-* attribute and put the query string inside that, something like data-qsv="query_string_value".
@RussellUresti that's a great idea, looser coupling
1

This only makes sense to me as non-javascript:

<form action="" method="get">
   <input type="submit" name="button" value="button 1" />
   <input type="submit" name="button" value="button 2" />
   <input type="submit" name="button" value="button 3" />
   <input type="submit" name="button" value="button 4" />
   <input type="submit" name="button" value="button 5" />
</form>

That's plain old HTML's way of passing buttons on the QS, could you clarify / give example of your situation?

Comments

0

IF you are having 5 submit buttons then you can submit and get the values using GET methods.If that is not the case and you need to specify how are you reaching the other pages.

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.