复选框填充表单字段 [英] Checkbox Populate Form Fields

查看:177
本文介绍了复选框填充表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用复选框填充表单字段。



用户流程示例:

访问者填写例如名称,地址,邮政编码,城市等。<
访问者可以选择复选框自动填充帐单信息字段。

如果用户选中与帐单信息相同复选框,将包含输入数据的运费信息字段\\ b $ b复制/粘贴到结算信息字段中。



请访问:



如果您要在取消选中时删除这些值,只需



我没有测试这个,但希望这将为你工作


I wish to use a checkbox to populate form fields.

Example User Flow:
Visitor fills out shipping info fields like name, address, zip, city.
Visitor has option to checkbox to auto populate billing info fields.
If user checks "same as billing info" checkbox, the shipping info fields
with input data are copy / pasted into billing info fields.

Please visit: http://staelements.com/register

Is J$ is best way to achive this?
Please tell me if there is a better solution.
Thanks for your attention good citizen!

解决方案

you can use Jquery to achive this .. first load the propery jquery library to your project or page ..

then if your checkbox is like this

<input type="checkbox" id="checkbox1" />

<!-- account form fields  -->
<input type="text" id="name" />
<input type="text" id="phone" />

<!-- billing form fields-->
<input type="text" id="name_billing" />
<input type="text" id="phone_billing" />

$(document).ready(function(){
 $("#checkbox1").change(function() {
  if(this.checked) {
   alert("checked ");
    //get the values of the filled fields
    $name = $("#name").val();
    $phone = $("#phone").val();
    console.log("name");
    // then add those values to your billing infor window feilds 

    $("#name_billing").val($name);
    $("#phone_billing").val($phone);

    // then form will be automatically filled .. 

  }
  else{
   $('#name_billing').val('');
   $("#phone_billing").val('');
  }
 });
});

check the js fiddle http://jsfiddle.net/2kt0usfx/

if you want to remove the values when uncheck , just

I did not test this , but hope this will work for you

这篇关于复选框填充表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆