I have a select dropdown and I want to make something that when the user chooses the value in the select dropdown, the selected text goes into an input box (which I can make hidden and can post).
I have this code so far:
<select name="klant" id="selectList" style="width: 250px">>
<option value="0000">---Select Customer---</option>
<?php echo $options;?>
</select>
<input type="text" id="mytext">
I have the following javascript to do the job but this does not work. Nothing gets inserted in the input box.
<script type="text/javascript">// <![CDATA[
$('#selectList').val();
$('#selectList :selected').text();
var foo = $('#selectList :selected').text();
document.getElementById("mytext").value = foo ;
// ]]>
</script>
What am I doing wrong?
$('#selectList :selected').text();returns your selected value? And why are you mixing jquery and javascript when selecting elements?jQuery? I only ask because you haven't tagged it in your question Also you haven't set an event listener if you are expecting the value ofmytextto change when the client changes theoption