SQL PHP HTML ASP JavaScript articles and free scripts to download
 

JavaScript link of a string object

We can declare a string and add a hyper link to the string. Here is one simple example of adding a link to a string.

my_string= new String("Welcome to plus2net.com");
document.write(my_string.link("http://www.plus2net.com"));

We will modify the above code a bit and or change dynamically the associated link of the string by clicking a radio button. You will visit google or Yahoo based on the radio button you clicked.
Here is the code

<html>
<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function linkme(str){
my_string= new String("Take me to my Search Engine");
if(str=="google"){
document.write(my_string.link("http://www.google.com"));}
else{document.write(my_string.link("http://www.yahoo.com"));}
}

</script></head>
<body>

<input type=radio name=engine value='Google' onClick="linkme('google')";>Google <input type=radio name=engine value='Yahoo' onClick="linkme('Yahoo')";> Yahoo

</body>
</html>

Here is the demo

Google Yahoo

Found anything wrong or wants to improve the code by adding more features? Post your short comment here or use the Forum



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
String Functions
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer