1

I've got a webform setup on Drupal 7, with mmulti-pages and using the same page conditional add-on (actually its now part of the webform 4 core, and it works fine)

At the start the webform asks for a firstname, surname. I want the javascript to take the entered values (using .change()) and prepopulate the billing firstname and surname on page 5 of the same webform.

This is the JS function:

(function ($) {
$(document).ready(function(){
    $('#edit-submitted-name-layout-firstname, #edit-submitted-name-layout-surname').change(function(){
        var fName = $('#edit-submitted-name-layout-firstname').val();
            sName = $('#edit-submitted-name-layout-surname').val();

                    alert("This is the firstname" + fName + "and Surname " + sName);
        $('#edit-submitted-bill-name-layout-billing-firstname').val(fName);
        $('#edit-submitted-bill-name-layout-billing-surname').val(sName);
        });
});
})(jQuery);

I've setup the webform-form-NID.tpl.php file, and to test it I popped in an alert as seen above - it works fine and prints out the entered firstname and surname values.

However, when I get to page 5 on the webform, the billing firstname and surname fields are blank? Could it have something to do with the multi-page element of the form?

Paddy

  • 1
    I'm guessing multipage is hiding some parts of the form. In that case, the hidden parts won't be available for dom manipulation. – Ollie Apr 14 '14 at 15:46
  • Whilst they won't be available in the DOM they will be available server side, so you could set the values using hook_form_alter. – Felix Eve Apr 14 '14 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.