/    Sign up×
Community /Pin to ProfileBookmark

Adding random number to HTML form

Hi,

I have a pretty basic HTML form, it doesn’t go to a database or anything, it just gets emailed directly to the owner of the website with their customer query. However, the owner has now asked that each query be assigned a random reference number of no more than 16 digits which must also be visible to the customer. I presume this will be relatively easy but I’m a complete beginner with Javascript which I assumed would be necessary for generating the number. I’ve sort of figured out how to generate the number but I can’t figure out how to get that number into a read-only field on the form so that it will be both visible to the client and sent with the rest of the data on the form to the owner.

I’ve had a number of attempts but this is what I’m trying at the moment:

[CODE]<html>
<head>
<title>xxx</title>
</head>
<script language=”javascript” type=”text/javascript”>
function randomnumber() {
document.form.randomnumber.value=(Math.round(Math.random()*9999999999999999+1));
}
</script>
<form>
<input name=”randomnumber” readonly>
</form>

</body>
</html>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 29.2009 — You need an event to fire the function. It might be [B]onload[/B]:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function randomnumber() {
document.forms[0].randomnumber.value=(Math.round(Math.random()*9999999999999999+1));
}
onload=randomnumber
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=""&gt;
&lt;input name="randomnumber" readonly&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@aa26iNov 20.2011 — Hi there,

I am new to this stuff. but this is what i am looking for, a random number on the form but what is required now that How can this random number be submitted with the form submit so that the same number appear in the spreadsheet too.

Multiple users submitting the form at the same time and each should get the (non-repeated) different random number which will go static with the form submission so that with other entries in spreadsheet like name job address etc one more column for this random number to be appear there as it is with their details to easily traceable for user and the administrator later.

I know the post is very old but hopefully i get some help here becoz still did not find any help on Google docs (no is replied to my post till now)

Thanx in advance
×

Success!

Help @DiscoverySquare spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...