Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2004, 10:18 AM
Authorized User
 
Join Date: Jun 2004
Location: Georgetown, Selangor, Malaysia.
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default Button linking question

Hello, if I use html code to create a button, can javascript make the button able to link to other page or site after the user has clicked the button? If yes, how it is done?

 
Old September 16th, 2004, 10:57 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
<html>
<head>
<title>Add Link Button</title>
<script type="text/jscript">
  function addLinkButton(Url)
  {
    var oContainer = document.getElementById("divButtons");
    var oButton = document.createElement("input");
    oButton.type = "button";
    oButton.value = "Go to '" + Url + "'";
    oButton.setAttribute("link", Url);   
    oButton.onclick = function(){alert(this.link); window.open(this.link);};
    oContainer.appendChild(oButton);
    var oBr = document.createElement("br");
    oContainer.appendChild(oBr);
  }  
</script>
</head>

<body bgcolor="#FFFFFF">
<input type="button" value="Add Button" onclick="addLinkButton(document.getElementById('txtLink').value);">&nbsp;<input type="text" size="40" id="txtLink">
<div id="divButtons"></div>
</body>
</html>
--

Joe
 
Old September 16th, 2004, 04:00 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Is Joe's solution what you were looking for? I thought you just wanted a simple button that when clicked took you somewhere like this:

<button onclick='window.location="nextpage.htm"'>next</button>

HTH,

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once.
 
Old September 18th, 2004, 05:05 AM
Authorized User
 
Join Date: Jun 2004
Location: Georgetown, Selangor, Malaysia.
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default

Oh, thanks a lot for the help, and sorry for replying late. Ya, Snib, you are right, I just want to have a simple button which is able to linking only. Anyhow, thanks for joe(can I address you such this?) for your coding, even though what I am looking for is a simple solution, but yours give me an alternative way, thank you. :)

 
Old September 18th, 2004, 05:43 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by hlchuah77
 Anyhow, thanks for joe(can I address you such this?):)
Sure you can, yes it was a bit complicated, I obviously thought you wanted to create the whole thing using JavaScript code, not just use code to link:)

--

Joe




Similar Threads
Thread Thread Starter Forum Replies Last Post
static linking question mwindham BOOK: Professional Assembly Language 1 April 24th, 2007 11:51 AM
Question For Button.PostBackUrl potato ASP.NET 2.0 Basics 2 March 19th, 2007 10:24 AM
Command Button Question eoghang Excel VBA 2 September 25th, 2006 08:33 PM
Question regarding linking and moving - any advice Kirok Java Basics 1 November 10th, 2005 10:32 AM
button question ExxWhyZee Flash (all versions) 2 January 31st, 2004 06:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.