Add text in hubspot form problem
I have a page which has a form in it from hubspot.
I am not able to input a text in 开发者_如何学Pythona text input field using javascript...
Please help I dont know the reason why..
<form action="http://www.xyz.com/Default.aspx?app=iframeform&hidemenu=true&ContactFormID=45875" method="post">
<input type="hidden" name="FormSubmitRedirectURL" id="FormSubmitRedirectURL" value="www.xyz.com/test" >
<input type="hidden" name="Lead_Src" id="LeadSrc" value="test form 1" />
<script type='text/javascript' language='javascript'>/* <![CDATA[ */
HubSpotFormSpamCheck_LeadGen_ContactForm_45875_m0 = function() {
var key = document.getElementById('LeadGen_ContactForm_45875_m0spam_check_key').value;
var sig = '';
for (var x = 0; x< key.length; x++ ) {
sig += key.charCodeAt(x)+13;
}
document.getElementById('LeadGen_ContactForm_45875_m0spam_check_sig').value = sig;
/* Set the hidden field to contain the user token */
var results = document.cookie.match ( '(^|;) ?hubspotutk=([^;]*)(;|$)' );
if (results && results[2]) {
document.getElementById('LeadGen_ContactForm_45875_m0submitter_user_token').value = results[2];
} else if (window['hsut']) {
document.getElementById('LeadGen_ContactForm_45875_m0submitter_user_token').value = window['hsut'];
}
return true;
};
/*]]>*/</script>
<script type="text/javascript">// <![CDATA[
document.getElementById('LeadGen_ContactForm_45875_m0_FirstName').value='test';
// ]]></script>
<input type='hidden' id='LeadGen_ContactForm_45875_m0submitter_user_token' name='LeadGen_ContactForm_45875_m0submitter_user_token' value='' /><input type='hidden' name='ContactFormId' value='45875' /><input type='hidden' id='LeadGen_ContactForm_45875_m0spam_check_key' name='LeadGen_ContactForm_45875_m0spam_check_key' value='snopseihlijderqjslqlrsqodlghlksnmpikgsphnegufklwnwtdsfeeegkr' /><input type='hidden' id='LeadGen_ContactForm_45875_m0spam_check_sig' name='LeadGen_ContactForm_45875_m0spam_check_sig' value='' /><div class='ContactFormItems FormClassID_45875'><table border="0" cellspacing="0" cellpadding="5">
<tr><td> </td><td>First Name</td></tr>
<tr><td> </td><td><input type="Text" name="LeadGen_ContactForm_45875_m0:FirstName" class="StandardI AutoFormInput LeadGen_ContactForm_45875_m0_AutoForm" id="LeadGen_ContactForm_45875_m0_FirstName" value="" /><div class="fieldclear"></div></td></tr>
<tr><td> </td><td>Last Name</td></tr>
<tr><td> </td><td><input type="Text" name="LeadGen_ContactForm_45875_m0:LastName" class="StandardI AutoFormInput LeadGen_ContactForm_45875_m0_AutoForm" id="LeadGen_ContactForm_45875_m0_LastName" value="" /><div class="fieldclear"></div></td></tr>
<tr><td> </td><td>Email (we will keep your email completely private)</td></tr>
<tr><td> </td><td><input type="Text" name="LeadGen_ContactForm_45875_m0:Email" class="StandardI AutoFormInput LeadGen_ContactForm_45875_m0_AutoForm" id="LeadGen_ContactForm_45875_m0_Email" value="" /><div class="fieldclear"></div></td></tr>
<tr><td> </td><td>Message</td></tr>
<tr><td> </td><td><textarea type="Text" name="LeadGen_ContactForm_45875_m0:Message" class="StandardI AutoFormInput LeadGen_ContactForm_45875_m0_AutoForm" id="LeadGen_ContactForm_45875_m0_Message" > </textarea><div class='fieldclear'></div></td></tr>
The test value is not being displayed..
the only way to put the javascript is in the head tags... and i get this message
Uncaught TypeError: Cannot set property 'value' of null
You have an extra }
in the second javascript tag.
<script type="text/javascript">// <![CDATA[
document.getElementById('LeadGen_ContactForm_45875_m0_FirstName').value='test';
} // <--- this one!!
// ]]></script>
I am unsure if you are copying and pasting the form from the source or if you are putting your own form in manually rather than having Hubspot generate it, but if it is a Hubspot form, then check out this article: http://blog.chooseimpulse.com/development/javascript-and-jquery-plugins-not-working-with-hubspot-forms
Hubspot forms are loaded by Javascript, and because of this the form might not of loaded when the script has been executed.
精彩评论