Sunday, February 20, 2005

Javascript Forms and Buttons

Here's the oldie but goodie script for a Close Window button:

<input name="button" type=button onClick="javascript:self.close();" value="Close Window">

Wondering if I can replace the "javascript:self...." with some code to enable the script to open a new page when it's clicked?

If you'd want the button to open a new page in the same window, you can use the location.href method. I'm personally a fan of putting stuff like this in functions, rather than cramming all of the code into the input tag like this:

<script type="text/javascript">
function gothere(){
location.href="path_to_new_page";
}
</script>

Then, you can use this for your button code:

<input type="button" onclick="gothere();" />

0 Comments:

Post a Comment

<< Home