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
naga kiran 2naga kiran 2 

javascript in vf page not working please correct it

<apex:page >
<script type="text/javascript">
function validate()
{
document.getElementById('demo').innerhtml='hello js'
}
</script>

  <html>
  <body>
  <h1>Congratulations</h1>
  <p id="demo">This is your new Page: js1</p>
  <apex:form >
       <apex:commandButton value="Insert" onclick="validate();"/>
       </apex:form>
  </body>
  </html>
  
</apex:page>
Best Answer chosen by naga kiran 2
Virendra ChouhanVirendra Chouhan
Hello Kiran,

Javascript is casesensitive so use "innerHTML" instead of "innerhtml".
document.getElementById('demo').innerHTML='hello js'

ONe more thing, command button will reload you vf page after clicking it. Here you can user HTML input button as well.
<input type="button" value="Insert" onclick="validate();"/>

 

All Answers

naga kiran 2naga kiran 2
Hi devanshu it did nt work...nochanges occur when i click the button
Devanshu soodDevanshu sood
<apex:page >
<script type="text/javascript">
function validate()
{
document.getElementById("demo").innerHTML="hello js";
}
</script>

  <html>
  <body>
  <h1>Congratulations</h1>
  <p id="demo">This is your new Page: js1</p>
  <apex:form > 
       <apex:commandButton value="Insert" rerender="demo" onclick="validate();"/>
       </apex:form>
  </body>
  </html>
  
</apex:page>

try this ...its working fine for me
Virendra ChouhanVirendra Chouhan
Hello Kiran,

Javascript is casesensitive so use "innerHTML" instead of "innerhtml".
document.getElementById('demo').innerHTML='hello js'

ONe more thing, command button will reload you vf page after clicking it. Here you can user HTML input button as well.
<input type="button" value="Insert" onclick="validate();"/>

 
This was selected as the best answer