Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate a dropdown issue 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

I have two dropdowns when a value is selected in one i want to set the value of another. The code i am using gets the value of the first but won't populate and no error!

Thanks for any help.


Here is the Javascript

Code:
function function1(Call_Result) {

    var result = (Call_Result.options[Call_Result.selectedIndex].value);
    if (result == "Hoax") {
        //alert("hoax"); 
		
		document.forms[0].[_recordmanager.selectedIndex].value = "user2";
		return false;
		//document.forms[0].[_recordmanager.selectedIndex].value = "";
    } 
    //alert("SelectedIndex value = "+result); 
}

Here is a striped out version of the page that can be saved as a .html file and tested

Code:
<html>

<head></head>



<body>



<tr><td class=ContactBoldText>Call Result </td>
<script language="Javascript">

function function1(Call_Result) {

    var result = (Call_Result.options[Call_Result.selectedIndex].value);
    if (result == "Hoax") {
        alert("hoax"); 
		
		_recordmanager.options[_recordmanager.selectedIndex].value = "user2";

    }
    
} 

</script>

<td class=ContactBoldText>
<select name=_Call_Result" onChange="function1(this);">
    <option value="" selected></option>
    <option value="Hoax" selected>Hoax</option>
    <option value="Not Interested">Not Interested</option>
    <option value="No Answer">No Answer</option>
    <option value="Booking">Booking</option>
</select>
</td></tr>

<tr><td class=ContactBoldText>Record Manager </td>

<td class=ContactBoldText><select name="_recordmanager" id=rmanager class=ContactsmallTextField  format=RecordManager>
<option noval="Administrator" value="czp19of2qr92rov9">Administrator</option> 
<option noval="Michael RutherFord" value="czp19of2qr68rtv9">Michael RutherFord</option> 
<option noval="sales" value="2aq17i72uydbk991">sales</option> 
<option noval="user1" selected value="f1q12ua3isgdhxn8">user1</option> 
<option noval="user10" value="k1q1q8l2a4eevqzg">user10</option> 
<option noval="user11" value="k1q149l2g8d5zlug">user11</option> 
<option noval="user12" value="k1q1lal29e04mc0b">user12</option> 
<option noval="user13" value="k1q1wal24m178db4">user13</option> 
<option noval="user14" value="k1q1abl2r803a937">user14</option> 
<option noval="user15" value="k1q1hdl288fjy1v2">user15</option> 
<option noval="user16" value="k1q1sdl2dbfi02wh">user16</option> 
<option noval="user17" value="k1q16el2dh16voyi">user17</option> 
<option noval="user18" value="k1q1oel2y0q9cheg">user18</option> 
<option noval="user19" value="42q1fx73uq2in6be">user19</option> 
<option noval="user2" value="k1q140l2gd3lurmg">user2</option> 
<option noval="user20" value="k1q1kgl2yaef6f64">user20</option> 
<option noval="user3" value="k1q1h3l2p2160fya">user3</option> 
<option noval="user4" value="k1q1z4l2boo5ghvb">user4</option> 
<option noval="user5" value="k1q1e5l2ylpbq87l">user5</option> 
<option noval="user6" value="k1q1v5l2vlo48ea9">user6</option> 
<option noval="user7" value="k1q166l2hzc5x0h8">user7</option> 
<option noval="user8" value="k1q1s7l2023avnad">user8</option> 
<option noval="user9" value="k1q1c8l2jw1cuv96">user9</option> 
</select>
</td></tr>



</body>




</html>
 
Hi

craigward said:
[gray](...)[/gray] no error!
Interesting. It gives "_recordmanager is not defined" error to me, just as it has to.

Anyway, note that you are only assigning a new [tt]value[/tt] there, so no selecting/populating will happen. By the way, what would you want exactly ?

Feherke.
 
Hi,

Thanks for the reply. I would like to select the value "Hoax" from the first dropdown and to have the value of the second dropdown be set to "user2"

Thanks again
 
Thanks for the link, great example. I have got one problem, the visual value of the second dropdown changes but the actual value doesn't get added, if you view the source of your page the second dropdown has no options even though you can see the number.

Is there away to set that dynamically? Reason being there is a database that gets updated by the value of the second dropdown.

Thanks again great bit of code.
 
Just as a suggestion, I've lately been using Matt Kruse's DynamicOptionLists from
After a bit of monkeying around it works great.

I'm generating the linked lists using PHP from a mySQL database, but I suppose any scripting would work, even hard-coding.

Here's an example that definitely works. You need all the bits, BODY, INPUT names, etc.

Code:
<script type="text/javascript" language="javascript1.2" src="DynamicOptionList.js"></script>
<script type="text/javascript" language="javascript">

[COLOR=red]
var Location = new DynamicOptionList();
Location.addDependentFields("FK_Department","FK_Title");
[/color]
Location.selectFirstOption = true;

Location.forValue(1).addOptionsTextValue('----- Select Title -----','');
Location.forValue(1).addOptionsTextValue('Chief Executive',2);
Location.forValue(1).addOptionsTextValue('Administrator',30);
Location.forValue(2).addOptionsTextValue('----- Select Title -----','');
Location.forValue(2).addOptionsTextValue('Communications Assistant',3);
Location.forValue(2).addOptionsTextValue('Head of Communications',12);
Location.forValue(2).addOptionsTextValue('Marketing Officer',22);
Location.forValue(2).addOptionsTextValue('Volunteer Support Officer',31);

 </script>
</head>
</head>
<body [COLOR=red]onLoad="initDynamicOptionLists();"[/color]>
<form>
<select name="[COLOR=red]FK_Department[/color]" id="fk_department" size=1>
<option value="">----- Select Department -----
</option>
<option value=1>xxxXXXxxx</option>
<option value=2 selected>Communications Team</option>
</select>
<select name="[COLOR=red]FK_Title[/color]" id="fk_title" size=1></select>
</form>

Download DynamicOptionList.js from javascripttoolbox or if you want, download the attachment, I think that is a later version I got from Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top