user1032531
user1032531

Reputation: 26281

Link button with data in url

I would like to make a button link to another page. Furthermore, I would like to include some data in the url. The onclick method works, but I was trying to do it without JavaScript. The form submit method almost works, but does not send the data (id1 and id2). Any suggestions? Is it best to use JavaScript? Thank you

<input type="button" value="Clickable Button - onclick" onclick="window.location.href='http://www.google.com?id1=123&amp;id2=345'" />

<form action="http://www.google.com?id1=123&amp;id2=345"><input type="submit" value="Clickable Button - Submit" /></form>

Upvotes: 0

Views: 816

Answers (3)

gopi1410
gopi1410

Reputation: 6625

Below is a non-js solution:

 <form method="get" action="http://www.google.com">
    <input type="hidden" name="id1" value="123" />
    <input type="hidden" name="id2" value="345" />
    <input type="submit" value="Clickable Button - Submit" />
 </form>

Upvotes: 2

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201588

<form action="http://www.google.com">
<input type="submit" value="Clickable Button - Submit" />
<input type="hidden" name="id1" value="123" />
<input type="hidden" name="id2" value="345" />
</form>

A better alternative, though, is to use a normal link and use CSS to style it look like a button if necessary. Links Want To Be Links.

Upvotes: 1

antyrat
antyrat

Reputation: 27765

You need to add some hidden fields to your <form>:

<form action="http://www.google.com">
    <input type="hidden" name="id1" value="123" />
    <input type="hidden" name="id2" value="345" />
    <input type="submit" value="Clickable Button - Submit" />
</form>

Upvotes: 4

Related Questions