944,164 Members | Top Members by Rank

Ad:
Feb 2nd, 2006
0

buttons in html

Expand Post »
Hello,
how do you add a custom button to a webpage and link it to another page? ANother question is how can you make the button rollover when someone's mouse is over the button and when they click the button? Would I need javascript?
Thanks
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Feb 3rd, 2006
0

Re: buttons in html

To create a button, use the "input" tag, with the type attribute set to "button":

<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)
  1. <input
  2. type ="buttton"
  3. id = "myButton"
  4. 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)
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. a:link, a:visited
  5. {
  6. float: left;
  7. margin: 2px 5px 2px 5px;
  8. padding: 2px;
  9. width: 100px;
  10. border-top: 1px solid #cccccc;
  11. border-bottom: 1px solid black;
  12. border-left: 1px solid #cccccc;
  13. border-right: 1px solid black;
  14. background: #cccccc;
  15. text-align: center;
  16. text-decoration: none;
  17. font: normal 10px Verdana;
  18. color: black;
  19. }
  20.  
  21. a:hover
  22. {
  23. background: #eeeeee;
  24. }
  25.  
  26. a:active
  27. {
  28. border-bottom: 1px solid #eeeeee;
  29. border-top: 1px solid black;
  30. border-right: 1px solid #eeeeee;
  31. border-left: 1px solid black;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <a href="#">Button 1</a><a href="#">Button 2</a><a href="#">Button 3</a>
  37. </body>
  38. </html>

Replace the "#" sign in the href tags, with the actual URL of the target page.

This technique will accomplish all your stated goals.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 3rd, 2006
0

Re: buttons in html

What about doing it without javascript. Like i have a button that I made, how can I put that on my page, and make it go to another page. Do you use </button> tags, and if you can how would you set the image as the button?
I like the css version, very clever.
Thanks
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Feb 3rd, 2006
0

Re: buttons in html

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.
Reputation Points: 8
Solved Threads: 6
Posting Whiz in Training
extofer is offline Offline
239 posts
since Aug 2005
Feb 3rd, 2006
0

Re: buttons in html

No, no no. Read the first part of my first reply. Buttons are made with "input" tags, and can be made to perform navigation tasks with the "onclick" attributes. Re-read the first part of my first reply.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 3rd, 2006
0

Re: buttons in html

I found a solution without using javascript:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <p><a href="#"><img src="some_image" width="150" height="50" border="0" id="button"/></a></p>
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Feb 3rd, 2006
0

Re: buttons in html

But that isn't a button... that's an image within a hyperlink.

Yes, if you want a hyperlinked image, you simply... make a hyperlinked image. :rolleyes:
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Aug 9th, 2010
0
Re: buttons in html
Reputation Points: 10
Solved Threads: 0
Light Poster
mariko is offline Offline
26 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Save the selected option through the site
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Insert javascript into input field





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC