Robert Hanson Robert Hanson - 6 months ago 12
Javascript Question

jQuery Select Failed To Change Input Value

I have this jquery inside PHP code :

echo '<select id="state" name="state" onchange="document.getElementById(\'state_text_content\').value=this.options[this.selectedIndex].text>
'.$list_state.'
</select>
<input type="hidden" name="state_text" id="state_text_content" value="" />';


why onchange function doesn't update
#state_text_content
value? thank you.

Answer
echo '<select id="state" name="state" onchange="document.getElementById(\'state_text_content\').value=this.options[this.selectedIndex].text">
    '.$list_state.'
</select>
<input type="hidden" name="state_text" id="state_text_content" value="" />';

Without seeing everything, I think it's because you have a typo. There is a missing quote at the end of the onchange=""

Comments