Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to add links on dynamic elements in list box?
Old 06-29-2006, 12:27 AM How to add links on dynamic elements in list box?
Junior Talker

Posts: 2
Trades: 0
Hi;

I want to add links on some of dynamic elements on list box. But I don't know how to do it. Below is my code, the links work only on static coding, what about the elements that are generated from array?

<script language="JavaScript">
var AUSTRIA = new Array("Dsche OHG","Attn: Mr. Wo Honger", "Bayerhamerstrasse 12bcc",
"A-5020 Salzburg", "Tel: +42 662 878891", "Fax: +42 662 879866","e-mail: wolfgang.holzinger@yahoo.com",
"www.hotmail.com");
var FISH = new Array("trout", "mackerel", "bass", "", "", "", "","");
var BIRDS = new Array("robin", "hummingbird", "crow", "", "", "", "","");

function swapOptions(the_array_name)
{
var numbers_select = window.document.the_form.the_examples;
var the_array = eval(the_array_name);
setOptionText(window.document.the_form.the_example s, the_array);
}

function setOptionText(the_select, the_array)
{

//for select box
for (loop=0; loop < the_select.options.length; loop++)
{
the_select.options[loop].text = the_array[loop];
}

}

function go()
{
box = document.the_form.the_examples;
destination = box.options[box.selectedIndex].value;
if (destination) location.href = destination;
}

</script>

<form name="the_form">
<select name="choose_category" onChange="swapOptions(window.document.the_form.cho ose_category.options[selectedIndex].text);">
<option selected>AUSTRIA
<option>FISH
<option>BIRDS
</select>

<select size="12" name="the_examples" onChange="go()" multiple>
<option>Dsche OHG
<option>Attn: Mr. Wo Honger
<option>Bayerhamerstrasse 12bacc
<option>A-5020 Salzburg
<option>Tel: +42 662 874891
<option>Fax: +42 662 879866
<option value="">e-mail: wolfgang.holzinger@yahoo.com
<option value="<A href="http://www.hotmail.com">www.eeoarms.com">http://www.hotmail.com">www.eeoarms.com
</select>

</form>


Thanks for your help!!!

Last edited by jsong; 06-29-2006 at 12:30 AM..
jsong is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-29-2006, 03:00 PM Re: How to add links on dynamic elements in list box?
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
I'm really confused by your code, it looks like you're using a <select> field for a <texarea> field... but to answer your question, you have to define the url for each option:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
window.onload = function() {
	var boxArray = new Array;
	
	var selectBox = document.createElement("select");
	selectBox.setAttribute("onchange","location.href=this.value;");
	
	boxArray[0] = new Option("Yahoo","http://www.yahoo.com");	
	boxArray[1] = new Option("Google","http://www.google.com");
	boxArray[2] = new Option("Sirius Ad","http://www.siriusad.com");
	boxArray[3] = new Option("Apple","http://www.apple.com");
	
	for (x in boxArray) {
		selectBox.appendChild(boxArray[x]);
	}
	
	document.getElementById("theForm").appendChild(selectBox);
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="theForm"></form>
	</body>

</html>
This will generate a box, and a set of links for each item. Is this what you mean?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 06-30-2006, 01:00 PM Re: How to add links on dynamic elements in list box?
Junior Talker

Posts: 2
Trades: 0
Thanks Funkdaddu.
jsong is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to add links on dynamic elements in list box?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15552 seconds with 12 queries