javascript in webform to populate a field.
It seems zoho still doesn't handle address fields in the deals module (only contact module). So I'd like to use the method I've been using for years on my old system, using javascript to populate the website field with a google maps url. I'm having trouble figuring out the syntax of the new webform. I remodel houses, I don't program javascript very well.
Previous webform script section:
gmapaddress=document.aptrequest.jobaddress.value.replace(" ","+");
while(gmapaddress.indexOf(" ")!=-1)
{gmapaddress=gmapaddress.replace(" ","+");}
This script would take the form field 'jobaddress'. Replace any spaces in the address with + and append that at the end of the google maps url in a new field 'gmap'. This was a hidden field in the form, sent along side the written address. This way from the email I could click on the hyperlink in this field to map the address. This works well as long as the lead enters their address into the form without misspelling. I can't recall the last time this happened.
I've created a new Lead->Deal field for 'project address' and 'projectmap'. I should be able to modify and insert my script above into the script portion of the code generated by Zoho CRM webform function (great function btw!) I've tried simply substituting the new field names and form name (aptrequest -> forms['WebToLeads2358863000000114001']) but that doesn't work. I've tried it with a period, quotes, square brackets, I've tried creating a new array like mndFileds with just 'pstreet' and 'Website' in it. So far none of my attempts even touch the 'Website' field that is emailed by the form or as it is created as a new lead.
I expect this will be a simple thing for someone who thoroughly understands javascript objects. Please help.
thanks
Everend
Script section generated by Zoho CRM.
- <script>
- var mndFileds=new Array('First Name','Last Name','Phone','LEADCF9','Description','LEADCF2','LEADCF4','LEADCF6');
- var fldLangVal=new Array('First Name','Last Name','Phone','Project Title','Description','Project Street Address','Project City','Project Zip Code');
- var name='';
- var email='';
- function checkMandatory() {
- for(i=0;i<mndFileds.length;i++) {
- var fieldObj=document.forms['WebToLeads2358863000000114001'][mndFileds[i]];
- if(fieldObj) {
- if (((fieldObj.value).replace(/^\s+|\s+$/g, '')).length==0) {
- if(fieldObj.type =='file')
- {
- alert('Please select a file to upload.');
- fieldObj.focus();
- return false;
- }
- alert(fldLangVal[i] +' cannot be empty.');
- fieldObj.focus();
- return false;
- } else if(fieldObj.nodeName=='SELECT') {
- if(fieldObj.options[fieldObj.selectedIndex].value=='-None-') {
- alert(fldLangVal[i] +' cannot be none.');
- fieldObj.focus();
- return false;
- }
- } else if(fieldObj.type =='checkbox'){
- if(fieldObj.checked == false){
- alert('Please accept '+fldLangVal[i]);
- fieldObj.focus();
- return false;
- }
- }
- try {
- if(fieldObj.name == 'Last Name') {
- name = fieldObj.value;
- }
- } catch (e) {}
- }
- }
- }
-
- </script>