I'm designing a registration form in PHP using html. The form collects personal info from users some fields include the marital status, name of spouse, and the number of children. How can I code it such that whenever a user selects "Single" for his/her marital status, the textboxes for the name of spouse and number of children will be automatically disabled? All of this must be done without refreshing the page. Thanks!
Assuming you are using drop down for marital status, use the onchange
event to capture the change in the drop down status
function maritalStatusChange()
{
var dropdown = document.getElementById("maritalstatus").value;
if(dropdown == 'Single')
{
document.getElementById("spousefld").readOnly = "readonly";
}
}
you can achieve this using the javascript function.
if you have used combobox for marrital status
<select id="a" onchange="if( this.options[this.selectedIndex].value=='s')
{document.getElementById('spouce').readOnly = true;}
">
<option value='s'>single</option>
<option value='m'>married</option>
</select>
<input type='text' id='spouce'/>
see the jsfiddle
You can use JS for your purpose. Try this code : (Assuming "single" is your radio button)
if (document.geElementById('maritalStatus').checked){
//disable resp textboxes
document.geElementById('spouce').disabled = true;
document.geElementById('children').disabled = true;
}
for more details see this
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.