| | |
buttons in html
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
To create a button, use the "input" tag, with the type attribute set to "button":
To make it perform an action, including navigating to another site, code the "onclick" attribute. The value will be a JavaScript function you've written and included elsewhere in the document (in the HEAD section, within SCRIPT tags), or will be inline JavaScript itself:
However, might I suggest another technique entirely? Use standard hyperlinks. Using CSS, you can make them look and behave exactly like buttons, with no JavaScript.
Replace the "#" sign in the href tags, with the actual URL of the target page.
This technique will accomplish all your stated goals.
<input type="button" id="myButton" /> To make it perform an action, including navigating to another site, code the "onclick" attribute. The value will be a JavaScript function you've written and included elsewhere in the document (in the HEAD section, within SCRIPT tags), or will be inline JavaScript itself:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<input type ="buttton" id = "myButton" onclick="self.location='destination_page.html';" />
However, might I suggest another technique entirely? Use standard hyperlinks. Using CSS, you can make them look and behave exactly like buttons, with no JavaScript.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <style type="text/css"> a:link, a:visited { float: left; margin: 2px 5px 2px 5px; padding: 2px; width: 100px; border-top: 1px solid #cccccc; border-bottom: 1px solid black; border-left: 1px solid #cccccc; border-right: 1px solid black; background: #cccccc; text-align: center; text-decoration: none; font: normal 10px Verdana; color: black; } a:hover { background: #eeeeee; } a:active { border-bottom: 1px solid #eeeeee; border-top: 1px solid black; border-right: 1px solid #eeeeee; border-left: 1px solid black; } </style> </head> <body> <a href="#">Button 1</a><a href="#">Button 2</a><a href="#">Button 3</a> </body> </html>
Replace the "#" sign in the href tags, with the actual URL of the target page.
This technique will accomplish all your stated goals.
Buttons are made with <form> tags. in it, you specify the destinations when it's presses. As for as rollovers, yes, there are custom bottons in javascript you can use.
Gabriel Villa
software development/ IT support consultant
software development/ IT support consultant
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 5
I found a solution without using javascript:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<p><a href="#"><img src="some_image" width="150" height="50" border="0" id="button"/></a></p>
![]() |
Similar Threads
- Newbies buttons/links (IT Professionals' Lounge)
- Random Spacing? (HTML and CSS)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Align right problem.
- Next Thread: How to end a session immediately when the browser closes?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box bug calendar cart checkbox class codes column createrange() css cursor date debugger decimal design dom download dropdown element embed enter error explorer firefox focus form frameworks getselection google gwt hiddenvalue hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 object onmouseover paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select shopping size software sql text textarea toggle unicode w3c website window windowofwords windowsxp wysiwyg







