I am making a form and making input field to read only using JavaScript. I change the default color for read only attribute. I want to display a default value when the field is readonly i-e "NIL"
HTML
<input type="radio" name="sex" value="male">Male<br/>
<input type="radio" name="sex" value="female">Female <br/>
Age:<input type="text" name="age" id="age" size="20">
Hobbies:<input type="text" name="hobbies" id="hobbies" size="20"><br/>
Phone:<input type="text" name="phone" id="phone" size="20"><br/>
JS
$("input[name='sex']").change(function() {
if($(this).val() == "female") {
$("#age,#phone").attr("disabled", true).css("background-color","#0F0");
} else if($(this).val() == "male") {
$("#age,#phone").attr("disabled", false).css("background-color","#FFF");;
}
});
I want add the default value "Nil" if the field is readonly. Kindly guide me how to add this property to my script.
readonlyelements, but the code included has no such elements and no attempt at setting content color, only background color. Please edit your question to be consistent and clear.