troubleshooting Question

Generate random number to SharePoint textbox on page load (JavaScript)

Avatar of IntercareSupport
IntercareSupport asked on
JavaScriptASP.NETMicrosoft SharePoint
5 Comments1 Solution2244 ViewsLast Modified:
I have a SharePoint 2010 textbox that I need to randomly generate an ID for on page load.  I think the code is good, but I don't think it correctly references the textbox.  The snippet is below, and the full code is attached.  I don't know how to programmatically reference the box, but I pulled the "aspnetForm.person_nbr" from the rendered HTML code.  Ideas?

<SCRIPT TYPE="TEXT/JAVASCRIPT">
_spBodyOnLoadFunctionNames.push("outrnd");
// Random number generator
function rnd(max) {
  var rndnum = max * Math.random()
  rndnum = Math.ceil (rndnum)
  return rndnum
}

// Call random number generator
function outrnd() {
  document.aspnetForm.person_nbr.value = rnd(9999)
}
</SCRIPT>

Original code from http://gwydir.demon.co.uk/jo/javascript/code.htm#random
code.txt
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros