Dear
Please try wrapping your javascript code with $( document ).ready(function() {});
Regards
Had a go, still comes back empty:
Is my code wrong?
Dear
Try again but wrap it with
window.onload = function() {
//Your Code Here
}
Regards
Dear Sharp
Ran some testings on your code , there was on problem with the DOM only .
here is the code (tested) should be working fine for you .
<script>
window.onload = function() {
debugger;
var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
var word = '';
while (word.length < 5){
var rand = Math.floor(Math.random() *characters.length);
addchar = characters.substring(rand,rand+1);
if(word.length == 0 && addchar >= 0 && addchar <= 9){}else{word+=addchar}
}
document.getElementById("result").innerHTML = word;
}
</script>
Regards.
With Ahmads help, got this working upon initialization.
I've tried to do a Save on the form, but the Save Method is saving the Data Label Javascript as the contents, rather the result of the javascript.i i.e my random number is 02as4 for example on screen, but the save method saves the javascript CODE itself.
Any ideas how to save the result? I tried transfer etc but no joy.
Thanks
I am not sure if this is the only way/or the correct way, but I have seen this works when attempting to set the text for a data label control:
var aTextField = "testing";
$("spannname='DataLabelName']").SFCLabel("option", "text", aTextField);
I think effectly finding the span with the data label according to its name and using this SFCLabel function to set the text
Hi Tin, Thanks for the info... with Ahamd's direction, i added the line and it looks like this: my data lable is called 'String Data Label'... but the result is an empty box.
<span id = "result"></span>
<script>
window.onload = function() {
var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz";
var word = '';
while (word.length < 5){
var rand = Math.floor(Math.random() *characters.length);
addchar = characters.substring(rand,rand+1);
if(word.length == 0 && addchar >= 0 && addchar <= 9){}else{word+=addchar}
}
$("spannname='String Data Label']").SFCLabel("option", "text", word);
}
</script>
Any ideas?
Thanks Tin, With your code and Amhads direction and a little tweeking got this working. For anyone else, here's the solution. I used Tins code, but added another Holding Data Label to the Form. Run the expression containing your javascript from the Holding Data Label. Then change Tin's one-liner to direct the output to your original Data Label name. I was then able to run a SAVE METHOD, and it successfully saved my Random Number..... phew I think the Expression and the Javascript on the same Data Label were fighting each other and it ends as a DRAW. So directing the javascript to a different Data Label ensures all parties are happy. Big thanks to Ahmad and Tin !!!!