How do I make this JavaScript go to a certain URL when it is clicked?

by on March 14, 2012

Q: I’ve got some CSS code for a custom button, how do I make it go to a url (example google.com) when someone clicks on it?

Here’s the code:

<!DOCTYPE HTML>
<html>
<head>
<style type=”text/css”>

input.groovybutton
{
font-size:17px;
font-family:Comic Sans MS,sans-serif;
font-weight:bold;
color:#FFFFFF;
width:125px;
height:35px;
background-color:#FF00CC;
}

</style>

<script language=”javascript”>

function goLite(FRM,BTN)
{
window.document.forms[FRM].elements[BTN].style.color = “#000000″;
window.document.forms[FRM].elements[BTN].style.backgroundColor =

“#FF00FF”;
}

function goDim(FRM,BTN)
{
window.document.forms[FRM].elements[BTN].style.color = “#FFFFFF”;
window.document.forms[FRM].elements[BTN].style.backgroundColor =

“#FF00CC”;
}

</script>

</head>
<body>

<form name=”groovyform”>
<input
type=”button”
name=”groovybtn1″
class=”groovybutton”
value=”Vote For Me!”
title=”"
onMouseOver=”goLite(this.form.name,this.name)”
onMouseOut=”goDim(this.form.name,this.name)”>
</form>

</body>
</html>


One Response to “How do I make this JavaScript go to a certain URL when it is clicked?”
  1.  

    This is actually pretty simple. All you do is add an onClick attribute. So add in something like

    onClick=”parent.location=’http://www.askageek.com/’”

    The problem here is your vote button doesn’t really do anything but my assumption is that you will pass a query string with the onClick that will do the voting so good luck!