+ Start a Discussion

javascript issue

havent used javascript before so I am testing a bare basic example but it wont work. Any suggestions would be helpful.

Also if someone can link me to some good examples of using javascript with visualforce , it will be great

<apex:pageBlockButtons id="pbButtons" location="bottom">
				<apex:commandButton id="btnSave" value="Save" onclick="javascript&colon;checkIds()"/>
				<apex:commandButton id="btnCancel" value="Cancel" action="{!loadOppPage}"/>
				<script src="/soap/ajax/15.0/connection.js" type="text/javascript">
					var btnSave = document.getElementById("{!$Component.btnSave}");
					funciton checkIds()
						window.alert('this works');




First of all i recommend you to use some javascript library, like jQuery. It is easy to use and learn at makes javascript much more easy.

Some tips:

       Dont catch elements by its ids if it are apex components, because the id is changed in the page proccess.

       With jQuery you can catch it by class.

       Or do it by the name.


Here is an example of how to do it: