...

View Full Version : Changing Text Value with a Select list.



Acaykath
03-18-2005, 10:20 PM
My final desire for what I am trying to do here is concatonate the item to the end of the value of the text input, but I simplified it since nothing was changing in the text field when changing the value of the select. It still has the same problem. The following is the code that I am using:



<select name='itemList" onchange="this.form.lootlist.value=this.options[this.selectedIndex].value">
<option value="">No Item</option>
$itemlist
</select>


$itemlist is a php variable containing all the options as they are generated from a database. Each is in the form of "<option value='#'># name</option>"

The current results are that nothing happens. Another problem is that the first two options don't appear... Is there a limit of 130 items in a Select form??

Acaykath
03-18-2005, 10:23 PM
ok I fixed that problem but now i have a new one... I got the javascript to work by fixing the quotes then I added back the stuff I removed, to simplify it and figure out what was wrong... and once again it isn't working.


<select name="itemList" onchange="
if (this.form.lootlist.value != "") {
this.form.lootlist.value = this.form.lootlist.value + "-"
}
this.form.lootlist.value =this.options[this.selectedIndex].value">
How can I get this to work??

_Aerospace_Eng_
03-18-2005, 10:43 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function addvalue(){
if(document.getElementById('lootlist').value != "")
document.getElementById('lootlist').value=document.getElementById('itemList').value;
}
</script>
</head>

<body>
<select id="itemList" name="itemList" onchange="addvalue()">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" id="lootlist" name="lootlist">
</body>
</html>
adapt it to fit your needs

Acaykath
03-18-2005, 11:05 PM
Unfortunately, I am not allowed to edit the template that contains the head, so I must have a script intermixed with the code. A script that will add values to a text field seperated by a "-" based on selections fron the list.

_Aerospace_Eng_
03-19-2005, 12:34 AM
<select id="itemList" name="itemList" onchange="if(document.getElementById('lootlist').value != ''){document.getElementById('lootlist').value=document.getElementById('itemList').value + '-';}">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" id="lootlist" name="lootlist">
will that work for you? and your original way might work if you change the double quotes in between the double quotes of the onchange to single quotes

<select name="itemList" onchange="if (lootlist.value != '') {
lootlist.value = lootlist.value + '-'
}
lootlist.value =this.options[this.selectedIndex].value"><option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" id="lootlist" name="lootlist">

Acaykath
03-19-2005, 02:06 AM
Thnx...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum