Can't add additional attributes to submit button


#1

I am trying to add additional attributes to the submit button. It says that we can add it through jquery but every time I inspect the element, it doesn’t show that it’s working. I tried the example they gave us of:

hbspt.forms.create({
portalId: ‘’,
formId: ‘’,
onFormSubmit: function($form) {
$(‘input[name=“firstname”]’).val(‘Brian’).change();
$(“input[type=submit]”).attr(“data-target”, “#confirmation”).change();
}
});

it does not change the value of the first name. I’m trying to add more attributes but it doesn’t seem to be recognizing any of them no matter where I try to add it.


#2

A few things to test here
Are you sure you want to make the change on submit? Perhaps you mean to use the “onFormReady” callback instead of “onFormSubmit”.

It might be better if you target the form specifically in the scope of your embed code.

$('input[name="firstname"]').val('Brian').change(); 

change to:

$form.find('input[name="firstname"]').val('Brian').change(); 

To help you debug better, try this code, and be sure your first name field is actually name=“firstname”

hbspt.forms.create({
portalId: '',
formId: '',
onFormReady: function($form) {
   $form.find('input[name="firstname"]').val('Brian'); 
} 
});

If the above code works, then start to sprinkle in the rest of your code