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
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
 
 
dchasmandchasman
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
damienmagnandamienmagnan
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 :


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


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.