Random Number Generation

User 2377814 Photo


Registered User
45 posts

Hi. I have been following Eric's script for inserting a random 9 digit number using a HTML element
http://www.coffeecup.com/forums/web-for … ce-number/
but on submission no number is generated.

<script src="common/libs_js/jquery-1.4.4.min.js"></script> <script type="text/javascript">$(document).ready(function(){
var number = 1 + Math.floor(Math.random() * 999999999);
//$("#item1").hide();
$("input[name='myfieldname']").val(number);

});</script>

In my own form the field is named RefNumber and the item is item40 (see below) and I want the field to be hidden from the user so have removed // from before //$("#item1") So I have edited the script as below:

<script src="common/libs_js/jquery-1.4.4.min.js"></script> <script type="text/javascript">$(document).ready(function(){
var number = 1 + Math.floor(Math.random() * 999999);
$("#item40").hide();
$("input[name='RefNumber']").val(number);

});</script>

I am using [RefNumber] to call up the result, but no number is being inserted into the form results.
This is the snippet of code which shows the item number:

<div class="fb-item fb-100-item-column" id="item40" style="opacity: 1;">
<div class="fb-html">
<div id="item40_div_0">

Could you help me please with what is wrong? Is there something else which needs editing?
Thank You
User 187934 Photo


Senior Advisor
20,271 posts
Online Now

Hi MG,
Can you share a link to the form?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.