Programming & Design
Question:
javascript button to take you to a link?
anonymous
2011-11-20 19:01:00 UTC
this is what I have so far but its not working
" />
Three answers:
Silent
2011-11-20 19:08:22 UTC
The value of the onclick attribute needs to be actual JavaScript code, not an HTML tag.
Two options:
1. onclick = "window.location = 'http://www.google.com';"
Note the use of single quotes around the URL.
2. Use an actual link instead of a button, and use CSS to make it look like a button.
a
2011-11-20 19:12:15 UTC
Oh boy....
You only use the anchor (
) element when making a regular link. For example, you can instead just do something like
Google
and create CSS styling to make it look like a button.
If you are trying to submit a form (which you may be trying to do seeing as you have an
element), then the
element should have the action="http://www.google.com/" property set. Then you can do onclick="submit()" in the input element.
Or, if you want to make the input button open a link closer to what you have, you would do
Of course, if you're going the JavaScript route instead of the regular HTML/CSS route for some reason, then a more ideal way may be to tag the button with an ID that you can bind with a click event to call a function to change the page.
Nicker
2011-11-20 19:10:36 UTC
SMH.....
You're new right? Please say yes, then I won't feel bad...
Here's the code you would need.
onclick="window.location.href='http://www.google.com'" />
Any more question? Feel FREE to email at fletchernick2@gmail.com.
EDIT:
DARN...Silent beat me to it..well still feel free to email me if u have any Q's.
*remove the line break between "type" and "onclick".*
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...