Sunday 15 September 2013

javascript - Copy field value from one field to another -


I need to copy two field values ​​from two different areas to their respective fields on the same page in another form. is. / P>

Input Field: First Name Input Field: Last Name

Copy these values ​​to these:

Input Field: Billing First Name Input Field: Shipping First Name < / P>

I have tried the following code to do no avail, I've hacked it from another website that has a checkbox for the same thing, in my case, the customer's first name, the last Name and email, one to enter the customer Clicks on Form Continue button again, and loads the next form, it would form where I want to first / last name autocomplete as early as.

This is the code that I am in the document.

  & lt; Script type = "text / javascript" & gt; Function Fill Billing (F) {if (f.dispatch [checkout.update_steps] .submit == true) {f.user_data [firstname] .value = f.user_data [b_firstname] .value; F.user_data [lastname] .value = f.user_data [b_lastname]. value; }} & Lt; / Script & gt;   

fields are generated in the form of default, unfortunately I can not change the ID nor the name value.

First name:

  & lt; Input type = "text" class = "input-text" value = "" size = "32" name = "user_data [first name]" id = "elm_6" & gt;   text = "User_data [lastname]" id = "elm_7" & gt;   

Continue button:

  & lt; Input type = "submit" value = "continue" name = "send [checkout.update_steps]" & gt;   

Billing First Name:

  & lt; Input type = "text" class = "input-text" value = "" size = "32" name = "user_data [b_firstname]" id = "elm_14" & gt;   

Billing last name:

  & lt; Input type = "text" class = "input-text" value = "" size = "32" name = "user_data [s_firstname]" id = "elm_16" & gt;   

I think, but may be wrong, because in the submit button there is a name in which dot (dispatch [checkout.update_steps]), it breaks javascript, but I Not sure

I have also noticed that the "first name", "last name" field and "continue" button are on a different form, data is sent through Ajax on another form on the same page is . In the first name, name = "step_one_contact_information_form" and the second form (the billing first name, billing last name) has the name = "step_two_billing_address".

Any thoughts?

Thank you for your advice!

I recommend that you make it with jQuery. It is very easy I made it for you :

Here is an example of code:

  $ ('input [type = submit]'). Val ($ ('# elm_14'). Val ($ ('# elm_6'). Val ()); $ ('# elm_16') Val ($ ('# elm_7'). Val ());}) ;    

No comments:

Post a Comment