javascript - Checkbox Populate Form Fields - Stack Overflow

I wish to use a checkbox to populate form fields.Example User Flow:Visitor fills out shipping info fie

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:

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

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./register

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

Share Improve this question edited Aug 15, 2014 at 4:59 Uncle Iroh asked Aug 15, 2014 at 4:47 Uncle IrohUncle Iroh 3866 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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/2kt0usfx/

if you want to remove the values when uncheck , just

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744413713a4573010.html

相关推荐

  • javascript - Checkbox Populate Form Fields - Stack Overflow

    I wish to use a checkbox to populate form fields.Example User Flow:Visitor fills out shipping info fie

    6天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信