...

View Full Version : Setting SELECTED in Select/List



Yarrokon
03-23-2009, 11:25 AM
Hello,

I'm trying to change the selected index of a List/Menu based on the value of a Text field, I can pull data and alerts, but setting the selection is not working. Any ideas?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function getExtension(){
var myType = document.form1.theExtension;
var daStr = document.form1.theList;
alert(myType.value);
for(var i = 0; i < document.form1.theList.length; i++){
alert(daStr.options[i].text);
if(daStr.options[i].text == myType.value){
daStr.options[i].selected == true;
alert("Yes");
alert(daStr.options[i].text.indexOf(myType.value));
}
else{
alert("No");
alert(daStr.options[i].text.indexOf(myType.value));
}
}
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<label for="theList"></label>
<p>
<select name="theList" id="theList">
<option>Make a Selection</option>
<option value="2">My DOC</option>
<option value="1">My PDF</option>
<option value="3">My XLS</option>
</select>
</p>
<p>
<label for="theExtension"></label>
<input name="theExtension" type="text" id="theExtension" value="My PDF" />
</p>
<p>
<label for="Button">Call It</label>
<input name="Button" type="button" id="Button" onclick="getExtension();" value="Call It" />
</p>
</form>
</body>
</html>


Thanks to anyone that can help or point me in the right direction.

tomws
03-23-2009, 02:16 PM
daStr.options[i].selected == true;

The double equal is a test for equality. Single is the assignment operator.

Yarrokon
03-23-2009, 06:22 PM
daStr.options[i].selected == true;

The double equal is a test for equality. Single is the assignment operator.
OMG, how did I miss that. This is what I get for working late, egg on my face.

Thank you for seeing this. :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum