Here are a simple script, for populating a text field from drop down,
for example how it works : user clicking on option 1, then the textfield showValue1 will filled/fired with 1a

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="theform" onsubmit="CheckForm()">
<select name="myOptions" onchange="document.theform.showValue1.value=this.value">
<option value="">Please select an option</option>
<option value="1a">1</option>
<option value="2a">2</option>
<option value="3a">3</option>
<option value="4a">4</option>
</select>
<input type="text" name="showValue1"><br>
</form>
</body>
</html>

now i need two to insert two value, in two text field together, when user choosing an option
for example : user clicking on option 1, then the textfield showValue1 will filled/fired with 1a,
and the the second textfield, lets say showValue2 will filled/fired with lets say 1b

i already tried added below in red, but its still not working

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="theform" onsubmit="CheckForm()">
<select name="myOptions" onchange="document.theform.showValue1.value=this.value [COLOR="#FF0000"]&amp; document.theform.showValue2.value2=this.value2[/COLOR]">
<option value="">Please select an option</option>
<option value="1a"[COLOR="#FF0000"] &amp; value2="1b"[/COLOR]>1</option>
<option value="2a"[COLOR="#FF0000"] &amp; value2="2b"[/COLOR]>2</option>
<option value="3a"[COLOR="#FF0000"] &amp; value2="3b"[/COLOR]>3</option>
<option value="4a"[COLOR="#FF0000"] &amp; value2="4b"[/COLOR]>4</option>
</select>
<input type="text" name="showValue">[COLOR="#FF0000"]<input type="text" name="showValue2">[/COLOR]<br>
</form>
</body>
</html>

please share your knowledge, how is the right code?

try this...

onchange="document.theform.showValue1.value=this.value.split(' ')[0]; document.theform.showValue2.value=this.value.split(' ')[2]">

note that if your final values in the dropdown have spaces in them you will need to adjust the split function calls accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.