Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a very simple html question

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
I want my user to be able to click a button and go to another web page. I want this button to just load a new page, nothing else.

I thought that I could do this by putting the button inside of a hyperlink.

<a href="../default.asp"><input type="button" value="try again" name="B3" tabindex="10"></a>

The button appears but clicking it does nothing. A text hyperlink with the same syntax works, so I know that my address is valid. I must be overlooking something obvious, please help.

 
It has to be a submit <input type='submit'... to use the type='button' you have to assign a function to the onClick event.




Chris.

Indifference will be the downfall of mankind, but who cares?
 
I made a small form with just the button on it, and that resolved the problem. But I still don't understand why I can't just use a hyperlink. In the old days you could put a button in a hyperlink, and it worked.
 
You can also do something like this in your HTML:

Code:
<input type='button' onclick='window.location="[URL unfurl="true"]http://www.google.com"'[/URL] value='Google' />

This uses javascript, but without having to write another function to do your task.

I think you SHOULD write a function, however. Something like:

Code:
function gotoSite(url)
{
 this.location = url;
}

...so that you can handle more than one button in the same fashion. For example:

Code:
<input type='button' value='Google' onclick='gotoSite("[URL unfurl="true"]http://www.google.com");'[/URL] />
<input type='button' value='Dictionary' onclick='gotoSite("[URL unfurl="true"]http://www.dictionary.com");'[/URL] />
...

'just my $0.02

'hope that helps!

--Dave
 
To use a "button" with an anchor tag, the buttin must be an image: <a href="../default.asp"><img src="images/button.gif"></a>. Using the <input type="button"> tag overrides the anchor tag.

There's always a better way. The fun is trying to find it!
 
Tviman, you raise a good point. In the "old days" I had .gifs of buttons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top