function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonny.KatesJonny.Kates 

Web-to-case with HTML4

Hi all,

 

I am finishing up a web-to-case form but have run in to what appears like a glaring oversight from Salesforce.

 

I have written some Javascript to validate the end-user's responses before the form is sent. Some fields have max values, some are mandatory etc. The Javascript will look through the DOM for a field's ID and then run its logic tests. However, form fields in HTML4 cannot begin with a number. For the web-to-case to work properly, I have to specify the HTML field's ID to match the Salesforce ID for that field - which of course, start with a number.

 

So I can either:

 

  • Run the web-to-case with no front end Javascript validation. However, validation will be respected on the Salesforce end, so if the user doesn't fill in a mandatory field and hits send; they will receive no notification that anything went wrong, neither will I, and everything they've written is lost as the transaction failed: no case created.
  • Add a leading character to the field IDs. This will mean the Javascript will work, but obviously the transaction to Salesforce will fail as the IDs now do not match: no case created.
  • Update the site to HTML5.

Obviously 3 is the only real choice, but this is slightly a pain and I did not anticipate having to do this for this piece of work. Salesforce should be transparent when you are setting up the web-to-case HTML that Javascript validation is not going to be possible on HTML4. It seems somewhat poorly thought out.

Best Answer chosen by Admin (Salesforce Developers) 
Jonny.KatesJonny.Kates

Found a solution.

 

Use:

 

document.getElementById('id')

 

instead of:

 

form.id

 

Bit messy, but it works

All Answers

Jonny.KatesJonny.Kates

Found a solution.

 

Use:

 

document.getElementById('id')

 

instead of:

 

form.id

 

Bit messy, but it works

This was selected as the best answer
sfdcfoxsfdcfox

That's in the help and training, by the way. Another solution is to use:

 

form['id']

Which is "less messy".

Jonny.KatesJonny.Kates

Oh cool, thanks :)