+ Start a Discussion
Bill HarrisBill Harris 

Client Side Javascript Validation in Visualforce

I am getting javascript error (null object) message while referencing inputbox. 
Problem: Visualforce is adding "j_id0:FormName:txtFirstName" in the Id
You are confusing the concept of the clientId (or dom id) we generate with the id attribute you set in the visualforce component - these 2 are related but definitely not going to be the same. The following info on Component IDs should clear things up. There are a number of reasons we generate guaranteed unique per page dom ids:

- duplicate ids cause very bad, inconsistent, behavior in different browsers (e.g. last one wins, first one wins) and are one of the most common causes of broken web apps
- we use this encoded dom id to be able to map back into the server side component model when actions are invoked (that is how the components find any posted data in the HTTP POST and update their values).

Message Edited by dchasman on 06-12-2008 09:08 AM
Well yes that's great... However I can't seem to access an object even if I use the good ID or if I use the $Component thingy :

alert(document.getElementById('{!$Component.testpage}'));//.style.backgroundColor = '#FF0000';

The alert messages are successively : "testpage", "[object HTMLDocument]" and "null", how can I make it work ? I'd like to recover an object to change its style for example.