I will pass value for multiple fields to a text field. There is a problem, checkbox. How to make sure that if the checkbox (allowance) only pass value to text field if user check it?
HTML:
<select id="Salary_para1">
<option value="">Choose...</option>
<option value="MYR" selected>MYR</option>
<option value="SGD" >SGD</option>
</select>
<input id="Salary_value" type="text"/>
+ <input type="checkbox" id="Salary_para2" name="Salary_para2" value=" + Allowance" />Allowance<br/>
<input type="text" id="targetTextField" name="targetTextField" size="31" tabindex="0" maxlength="99" value="">
CODE:
$(function() {
$("#Salary_para1").change(function(){
setTarget()
});
$("#Salary_para2").change(function(){
setTarget()
});
$("#Salary_value").keyup(function(){
setTarget();
});
});
function setTarget(){
var tmp = $("#Salary_para1").val();
tmp += $("#Salary_value").val();
tmp += $("#Salary_para2").val();
$('#targetTextField').val(tmp);
}
check if checkbox is
checked:http://jsfiddle.net/oceog/e2ScF/62/
(i made also some refactoring on orinal code)