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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making buttons DO THINGS

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
Maybe I'm just missing something, but for some reason I cannot get buttons to work regularly for anything! All I want is a button linking to another page. Is that possible without having a form?

Cyprus
 
form's and button's first go together. it's considered bad design not to surround form objects in <form> tags.

to use a button you need to specify a event to that button. (this excluding submit types)

eg:
<input type=&quot;button&quot; value=&quot;click&quot; onClick='window.alert(&quot;Hello!&quot;);'>

onClick being the event. (location.href='path' being a link)

reference events in javascript:

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
Plus you can have a form that contains nothing but the button if you want to (avoids Javascript, though the Javascript is cleaner imo):
Code:
<form action=&quot;yourpagename.htm&quot; method=&quot;POST&quot;>
    <input type=&quot;submit&quot; value=&quot;Go to my cool page&quot;>
</form>
 
If your button is a graphic, put it in an <A HREF> tag: <A HREF=&quot;<IMG SRC=&quot;images/buttonimage.jpg&quot; WIDTH=&quot;100&quot; HEIGHT=&quot;30&quot; BORDER=&quot;0&quot;></A>

There's always a better way...
 
Thanks for the jscript onpnt. All of these buttons are inside of a form, by the way but for cosmetic purposes I couldn't use individual forms for each. They work now. Thanks a lot guys!!

Cyprus
 
> for cosmetic purposes I couldn't use individual forms for each.

I'm guessing you mean that you don't want the gaps that get placed around forms by default. You can get rid of them with CSS like this:
[tt]
<form style=&quot;margin:0&quot; action=&quot;page1.htm&quot; method=&quot;POST&quot;>
<input type=&quot;submit&quot; value=&quot;Page 1&quot;>
</form>
<form style=&quot;margin:0&quot; action=&quot;page2.htm&quot; method=&quot;POST&quot;>
<input type=&quot;submit&quot; value=&quot;Page 2&quot;>
</form>
[/tt]
The javascript method, though &quot;cleaner&quot;, will not work at all for the 10% of people that surf with JS switched off.

-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top