I will pass value for multiple fields to a text field. There is a problem, select options, its value are 0 and 1, my question is how to make sure that it pass option text instead of 0 and 1? That mean pass MYR instead of 0 and SGD instead of 1?
HTML:
<select id="Salary_para1">
<option value="">Choose...</option>
<option value="0" selected>MYR</option>
<option value="1" >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() {
setTarget();
$("#Salary_para1,#Salary_para2").change(setTarget);
$("#Salary_value").keyup(setTarget);
function setTarget() {
var tmp = $("#Salary_para1").val();
tmp += $("#Salary_value").val();
tmp += $("#Salary_para2:checked").val() || '';
$('#targetTextField').val(tmp);
}
});
To get the text and not the value of whatever is selected in the dropdown, you’d have to target the selected option and get the text from that element :
FIDDLE