• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Additional Attributes -Random Number in text field

Additional Attributes -Random Number in text field 10 years 6 months ago #29224

  • lunakick
  • lunakick's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
I want to generate a random number that users will then use to name their file before uploading it, so that we use an anonymous review in looking at their form entry.

I have this in the Javascript:
<script type="text/javascript">
function Randoms(){
var randomNumber = Math.rand() * (1000 + 1);
randomNumber = Math.floor(randomNumber);
document.getElementById('randomNumber');}
</script>

And this in the Additional Attributes of a Textbox Field:

onclick="Randoms()";


But it's not populating the field on the form. Please help me figure out what I'm missing! Thanks a bundle!
The administrator has disabled public write access.

Additional Attributes -Random Number in text field 10 years 6 months ago #29233

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Please keep in mind that a random number will sometimes generate duplicates. However, for your scenario you will have to use something like this:
<script type="text/javascript">
function Randoms(){
	document.getElementById('field_name').value = Math.floor((Math.random() * 1000) + 1);
	}
</script>

and use the onclick="Randoms();" trigger on the field.

However please keep in mind that the above example will generate a random number everytime you click the field, so it's better to add a condition to the script:
function Randoms(){
	if (document.getElementById('field_name').value.length > 0){
		return false
		}
	else{
		document.getElementById('field_name').value = Math.floor((Math.random() * 1000) + 1);
	}
}
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!