Forum Moderators: open

Message Too Old, No Replies

<input type="button> to act like <a>?

I can do that right?

         

Emperor

3:32 am on Jul 13, 2005 (gmt 0)

10+ Year Member



Hi guys,

Can I make an <input type="button"> go to another page when clicked?

I think I have to do it in JavaScript don't I?

Thanks

birdbrain

11:10 am on Jul 13, 2005 (gmt 0)



Hi there Emperor,

try this, it may give you some ideas...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>button links</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<style type="text/css">
<!--
body {
background-color:#eef;
}
#container {
width:150px;
padding:4px 4px 0px 4px;
border:3px double #000;
background-color:#ccc;
margin:40px auto;
}
.butts {
font-family:verdana,sans-serif;
font-size:14px;
width:150px;
margin-bottom:4px ;
}
//-->
</style>
<script type="text/javascript">
<!--
function newPage(num) {
var url=new Array();
url[0]="http://www.htmlforums.com";
url[1]="http://www.codingforums.com.";
url[2]="http://www.w3schools.com";
url[3]="http://www.webmasterworld.com";
window.location=url[num];
}
// -->
</script>
</head>
<body>
<form action="#">
<div id="container">
<input class="butts" type="button" value="htmlforums" onclick="newPage(0)"/>
<input class="butts" type="button" value="codingforums" onclick="newPage(1)"/>
<input class="butts" type="button" value="w3schools" onclick="newPage(2)"/>
<input class="butts" type="button" value="webmasterworld" onclick="newPage(3)"/>
</div>
</form>
</body>
</html>

birdbrain

Trace

1:17 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



Is this all you need?

<input type="button" value="something" onClick="document.location.href('http://www.google.com');">

Emperor

3:36 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



That's all I needed guys, thanks.

Emperor

12:33 am on Jul 14, 2005 (gmt 0)

10+ Year Member



Hi again,

I just noticed it doesn't work in FireFox, and I have all the JavaScript features enabled.

I wonder why.

Trace

1:14 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



Sorry, wasn't thinking when I typed that up, use this;

<input type="button" value="something" onClick="document.location.href='http://www.google.com';">

And make sure you have it between <form> tags.