I have three input text boxes in my form.
First one is teacher, second one is grade. Now I’ve the third input text box, where i need to update the value dynamically from these two values as “(teacher)’s (X) class” using JavaScript.
Can anyone help me in writing the code?
Thanks in advance.
here is the jquery code:
<script type="text/javascript">
$(document).ready(function(){
$('#both').value($('#teacher').val() + "'s " + $('#grade').val());
});
</script>
and my input tags are:
<input type="text" name="teacher_name" id="teacher" value="" style="background:#f7f6f2 url(../images/input_02.png) repeat left top;border: 0px;width: 250px;height: 10px;padding: 10px;display: block;">
<input type="text" name="teacher_name" id="grade" value="" style="background:#f7f6f2 url(../images/input_02.png) repeat left top;border: 0px;width: 250px;height: 10px;padding: 10px;display: block;">
<input type="text" name="teacher_name" id="both" value="" style="background:#f7f6f2 url(../images/input_02.png) repeat left top;border: 0px;width: 250px;height: 10px;padding: 10px;display: block;">
what are the things i need to add to make my third input field to get updated.
Use the
onChangeevent that is triggered when an input content changes or theonBlurevent that is triggered when an input lost the focus:Or using jQuery, you can bind the event at
document.readyevent:DEMO