Reputation: 26281
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&id2=345'" />
<form action="http://www.google.com?id1=123&id2=345"><input type="submit" value="Clickable Button - Submit" /></form>
Upvotes: 0
Views: 816
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
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
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