Page 1 of 1

problem in displaying info

Posted: Sun Jan 04, 2004 10:09 am
by dakkonz
I want to display what the user has already submitted before in a form.
I am having problem displaying this select list.
My list is such a way that when the user choose CARS, another set of select options will be displayed and if BIKES is chosen there will be another set....
this code is on my edit page... I want to see what the user has chosen before.... I can only do it for the first select list... but cannot display whatever is it in the 2nd list

Code: Select all

<script language=javascript1.2>
IE = (document.all)?1:0;
NS = (document.layers)?1:0;
detail0 = '';

detailCARS='<option value="Porsche">Porsche</option><option value="Ferrari">Ferrari</option><option value="BMW">BMW</option>';

detailBIKES='<option value="Honda">Honda</option><option value="Phantom">Phantom</option>;

function ChangeDetail(pos) &#123;
	pos = pos.GENRE.options&#1111;pos.GENRE.selectedIndex].value;
	temp = '<select name="SUB">"<option value="0">Select a Sub-Genre</option>"' + eval("detail" + pos) + '</select>';
	if(IE)&#123;	newDetail1.innerHTML=(temp)&#125;
	else if(NS)&#123;
		document.newDetail1.document.write(temp)
		document.newDetail1.document.close()
		document.write("abcdef");
	&#125;
&#125;
</script>
<br><br><td><b>Selection:</b><select name="GENRE" onChange=ChangeDetail(this.form)>
<OPTION VALUE="0" selected>Select Genre</option>
<OPTION VALUE="CARS" <?php if (isset($g) && $g == "CARS") echo 'SELECTED';  ?>>Alternative Rock</option>
<OPTION VALUE="BIKES" <?php if (isset($g) && $g == "BIKES") echo 'SELECTED';  ?>>Blues</option>

</SELECT>
<BR>&nbsp&nbsp
  <div id=newDetail1> 
                                  <select name="SUB">
                                    <option value="0">-------------</option>
                                  </select>
                                </div>

Posted: Mon Jan 05, 2004 12:33 am
by Gen-ik
Not too sure what you mean exactly but if you are trying to set a <select> option using JavaScript you could do it like this...

Code: Select all

<body><script type="text/javascript">

function SelectIt(optionNum)
&#123;
    document.forms.myForm.mySelect.options&#1111;optionNum].selected = "selected";
&#125;

</script>

<form id="myForm">
<select name="mySelect">
<option value="Bikes">Bikes</option>
<option value="Cars">Cars</option>
<option value="Legs">Legs</option>
</select>
</form>

<a href="javascript:SelectIt(0)">Select Bikes</a><br />
<a href="javascript:SelectIt(1)">Select Cars</a><br />
<a href="javascript:SelectIt(2)">Select Legs</a>

</body>

To get the <select> options to jump to the right ones when the page first loads you could set <body onload="SetupOptions()"> and then use something like this...

Code: Select all

<head>

<script type="text/javascript">

function SetupOptions()
&#123;
    SetupSelect("myForm", "mySelect", 2);
    SetupSelect("myForm", "anotherSelect", 5);
&#125;

function SetupSelect(formName, selectName, optionNumber)
&#123;
    // formName = The name of the <form>
    // selectName = The name of the <select> object
    // optionNumber = The <option> number which is to be selected

    eval("document.forms." + formName + "." + selectName + ".options&#1111;" + optionNumber + "].selected='selected'");
&#125;

</script>

</head>

Hope that helps.

Posted: Tue Jan 06, 2004 8:06 am
by dakkonz
okay will go try it first...thanks