Kelly Hansen Kelly Hansen - 2 months ago 9
Javascript Question

Update Text Box On change Javascript

Im trying to update a text box when a selection changes.

Here is the code.

<script type="text/javascript">
$("#name").change(function () {
var selectedValue = $(this).val();
var result = string.substring(string.lastIndexOf(":") + 1);
document.getElementById('newname').value = result ;
});
</script>


Being an extream noob to this i dont understand why this is not working?
The #name is the dropdown list "selection" and the newname is the text box i want to update.

Answer

In the var result, string.substring, do you mean selectedValue.substring ?

<script type="text/javascript">
$("#name").change(function () {
    var selectedValue = $(this).val();
    var result = selectedValue.substring(selectedValue.lastIndexOf(":") + 1);
    document.getElementById('newname').value = result ;
});
</script>