简体   繁体   English

更新注册表单而不刷新页面

[英]Updating a registration form without refreshing a page

I'm designing a registration form in PHP using html. 我正在使用html设计PHP中的注册表。 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 假设您使用下拉菜单显示婚姻状况,请使用onchange事件捕获下拉菜单状态的更改

function maritalStatusChange()
{
    var dropdown = document.getElementById("maritalstatus").value;
    if(dropdown == 'Single')
    {
        document.getElementById("spousefld").readOnly = "readonly";
    }
}

you can achieve this using the javascript function. 您可以使用javascript函数来实现。

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 看到jsfiddle

You can use JS for your purpose. 您可以根据需要使用JS。 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 有关更多详细信息, 请参见此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM