You need to sign in to do that
Don't have an account?
Simple Javascript not working on visualforce page
I am having a really hard time trying to get this really simple bit of Javascript to work on this visualforce page. All I want to do is update a text box or outputText field with Todays date. It is being called onclick in a button.
Code:
<script type="text/javascript">
sforce.connection.sessionId = "{!$Api.Session_ID}";
function UpdateClockIn(textid){
alert("I am here");
var DateNow=New Date();
document.getElementById(textid).value=DateNow;
};
</script>
Called:
<button onclick="UpdateClockIn('{!$Component.Testing}');">Clock In</button>
The alert isn't even appearing on my screen which makes me believe the Javascript isn't running at all. Am I missing something?
your javascript function is having some issue
var DateNow=New Date();--------------------- This is incorrect
var DateNow=new Date(); --------------- correct one
Thanks,
bForce
Ok that fixed the first half but now it is not updating the field with the value. Thoughts on that? I used an alert to check DateNow and that is correctly filled. After a little bit more testing I have found that the field has accepted the value but is not displaying it. I believe what it might be is that it is counting the onclick as a submit. Is there a way I can prevent it from submitting and just have the field update?
Ok I have the submit stopped by doing this:
onclick="return UpdateClockIn()"
function UpdateClockIn() {
var DateNow;
DateNow=new Date();
document.getElementById(textid).value=DateNow;
return false;
}
The field is still not displaying the value though. The error is only with the outputText field. When I use it to display in my input field it works great. This is not a major issue anymore but if there are any thoughts as to why it doesn't work with outputText field that would be great.
outputtext displays the value so You may have to replace .value with .html to replace the html/text displayed.
or something like that