Hello and thanks for the help ahead of time. Note that I am new to this, which will probably explain why I can't figure out the issue.
I am trying to dynamically change the value of an input text field when the value of a dropdown is changed.
head of my page:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<script type="text/javascript" src="projectJS.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// initialize the value of the input field to the selected value
// of the dropdown list:
$("#membfee").val($("#role").val());
$("#role").click(function() {
// when the value of the dropdown list changes
// update the input field
$("#membfee").val("111");
});
});
</script>
</head>
I don't thing there are any issues with the jquery, it's all pretty simple. Are you able to reference an external javascript file and jquery like I did above?
Section of the body containing the dropdown menu and text field I wish to update:
<tr>
<td class="label_block">Membership Term:</td>
<td> <select name="role" id="role" />
<option value="Trial">Trial</option>
<option value="1 Month">1 Month</option>
<option value="3 Month">3 Month</option>
<option value="6 Month">6 Month</option>
<option value="Year">Year</option>
</select>
</td>
</tr>
<tr>
<td class ="label_block">Membership Fee:</td>
<td><input type="text" size="15" name="membfee" id="membfee" value="" /></td>
<td class="error">
<%out.print(membfee_msg);%>
</td>
</tr>
You should use .change()
:
$("#role").change(function() {
// when the value of the dropdown list changes
// update the input field
$("#membfee").val("111");
});
Are you sure there aren't any JS errors on the page, because it just should work .
Try using the change()
event instead:
$("#role").change(function(){
// blabla
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.