In the modified code below, I have two combo boxes with each one linked to the other. A description box updates itself on whichever value is chosen from the two selection boxes.
If you try the code below, clicking on 'Numbers' on the left menu will bring up a choice of '1' or '2'. When you choose '1', the description box brings up:
The number 1 rules!
The way I want it to show is:
The number
1 rules!
Basically, I need a break in the line. It seems that the quotation marks are what's keeping me from inserting html code to break up the line. Anyone have any idea on how to make the line break happen? The textarea code at the bottom is what drives the description box. I can control that, but I can't control the array. I appreciate any help and/or advice you can give.
Thanks,
Scootman
If you try the code below, clicking on 'Numbers' on the left menu will bring up a choice of '1' or '2'. When you choose '1', the description box brings up:
The number 1 rules!
The way I want it to show is:
The number
1 rules!
Basically, I need a break in the line. It seems that the quotation marks are what's keeping me from inserting html code to break up the line. Anyone have any idea on how to make the line break happen? The textarea code at the bottom is what drives the description box. I can control that, but I can't control the array. I appreciate any help and/or advice you can give.
Code:
<html><head></head><body>
<script language="JavaScript">
<!--
//Double Combo Box with Description Code- by Randall Wald ([URL unfurl="true"]http://www.rwald.com)[/URL]
//Visit JavaScript Kit ([URL unfurl="true"]http://javascriptkit.com)[/URL] for script
//Credit must stay intact for use
var num_of_cats = 3; // This is the number of categories, including the first, blank, category.
var open_in_newwindow=1; //Set 1 to open links in new window, 0 for no.
var option_array = new Array(num_of_cats);
option_array[0] = new Array("Please select a letter or number to the left"); // This is the first (blank) category. Don't mess with it.
option_array[1] = new Array("-- Select A Number Below --",
" 1 ",
" 2 ");
option_array[2] = new Array("-- Select A Letter Below --",
" A ",
" B ");
var text_array = new Array(num_of_cats);
text_array[0] = new Array("Here's how you use this box: First, you select a category in the Category drop-down. Then, select a link from the Link drop-down. Then, read the description in this box, or click Go to go to the page. If you ever need to see this help again, just go back to the top option in the Category box."); // These are general instructions. Change them if you want, or keep them if you don't.
text_array[1] = new Array("Pick A number from the box at left.", // Note that the first entry here is a general description of this category. After than, they're descriptions of each link. Make sure that you don't put the first link first; the general description must be first.
"The number 1 rules!",
"The number 2 is great, but not great!");
text_array[2] = new Array("Pick a letter from the box at left.",
"As a letter, A is awesome!",
"As a letter, B is...boring!");
var url_array = new Array(num_of_cats);
url_array[0] = new Array("#"); // The first category. This should have no items other than "#".
url_array[1] = new Array("#", // The second category; the first "real" category. Note the initial #. That is the category
"");
url_array[2] = new Array("#",
"");
function switch_select()
{
for (loop = window.document.form_1.select_2.options.length-1; loop > 0; loop--)
{
window.document.form_1.select_2.options[loop] = null;
}
for (loop = 0; loop <option_array[window.document.form_1.select_1.selectedIndex].length; loop++)
{
window.document.form_1.select_2.options[loop] = new Option(option_array[window.document.form_1.select_1.selectedIndex]
[loop]);
}
window.document.form_1.select_2.selectedIndex = 0;
}
function switch_text()
{
window.document.form_1.textarea_1.value = text_array[window.document.form_1.select_1.selectedIndex]
[window.document.form_1.select_2.selectedIndex];
}
function box()
{
if (window.document.form_1.select_2.selectedIndex == 0)
{
alert("Where do you think you're going?");
} else {
if (open_in_newwindow==1)
window.open(url_array[window.document.form_1.select_1.selectedIndex]
[window.document.form_1.select_2.selectedIndex],"_blank");
else
window.location=url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex]
}
}
function set_orig()
{
window.document.form_1.select_1.selectedIndex = 0;
window.document.form_1.select_2.selectedIndex = 0;
}
window.onload=set_orig
// -->
</script>
<form name="form_1" onSubmit="return false;">
<!-- This should be the same as the general instructions in the above code. -->
<select valign="top" name="select_1" size="3" onChange="switch_select(); switch_text();">
<option> </option>
<option> Numbers </option>
<option> Letters </option>
</select>
<select size="3" name="select_2" onChange="switch_text();">
<option> -- Please select a letter or number to the left -- </option>
<option> </option>
<option> </option>
</select>
<textarea style="overflow:hidden" readonly WRAP="off" name="textarea_1" rows=3 cols=38>
</textarea><br><br><br>
<input type="submit" onClick="box();" value="Go!">
</form>
<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"></font></p>
</body>
</html>
Thanks,
Scootman