You need to sign in to do that
Don't have an account?

Needed: Javascript to submit Checkbox
Hi
I need to use the terminology 'Email Opt In' with the checkbox on my Web-to-Lead form, but I want the form to submit the correct information to the Email Opt Out field in Salesforce.
This means I need the form to send the opposite value to Salesforce (ie 1 instead of 0) when the box is not checked.
I have been told by support that this can be done with a bit of javascript. Our webmaster has not been able to help.
I really need to get this sorted as soon as possible. Please can someone help?
<input type="checkbox" name="00N30000000xxxx" value="1" id="00N30000000xxxx" />
<label for="00N30000000xxxx">Yes, I'd like to be added to your e-mail list.</label>
In the submitform() function, add the following code, where "f" is the name of the form:
Here's what *should* happen:
However, if the email Opt-in checkbox is checked, then the "opt-out" tag will not be created!
All Answers
Hi
I have have tried to do this but without any luck.
Please can you post an example of the code that I would need to do this?
<input type="checkbox" name="00N30000000xxxx" value="1" id="00N30000000xxxx" />
<label for="00N30000000xxxx">Yes, I'd like to be added to your e-mail list.</label>
In the submitform() function, add the following code, where "f" is the name of the form:
Here's what *should* happen:
However, if the email Opt-in checkbox is checked, then the "opt-out" tag will not be created!
Hi
Sorry I have not replied earlier. This bit of code as just what I was looking for. I have added an else statement so that a 0 value is also submitted. The code javascript now looks like this:
function optin(){
if (document.getElementsByName('emailOptIn')[0].checked == false) {
optOut = document.createElement("input");
optOut.setAttribute("type", "hidden");
optOut.setAttribute("name", "emailOptOut");
optOut.setAttribute("id", "emailOptOut");
optOut.setAttribute("value", "1");
document.form.appendChild(optOut);
}
else {
optOut = document.createElement("input");
optOut.setAttribute("type", "hidden");
optOut.setAttribute("name", "emailOptOut");
optOut.setAttribute("id", "emailOptOut");
optOut.setAttribute("value", "0");
document.form.appendChild(optOut);
}
}
This code is used in the form to create the actual checkbox
<input value="1" type="checkbox" id="emailOptIn" name="emailOptIn" />
Where form is the name of the form on the Webpage
Thanks for your help
Hi CaptinObvious
You helped me before by providing a piece of JavaScript code which updated my Email Opt Out checkbox. I am now encounter another problem on the same form. We need to validate the information entered on our webforms before it is submited to Salesforce.
We have fields like First Name, Last name and Industry (Salesforce Standard fields) which we have not had a problem finding JavaScript validation code which seems to happily to sit along side the code you suggested. We have a problems when we also try to validate a custom picklist field called Region that we need to make compulsory which we are finding difficult as the script doesn't appear to accept the name/ID if it starts with 2 zeros. We seem to be able to either validate the information in the form or have the email opt out working but at the moment we can't get the 2 to work together.
Do you have any suggestions?
Hi Kerry,
Try the following:
Remember that "f" is the name of your form. See if that works for you.
Message Edited by CaptainObvious on 02-19-2008 10:21 AM