I will try to explain as simple as i can

head section
<script type="text/javascript">
function randomnumber() {
document.forms[0].randomnumber.value=(…
}
onload=randomnumber
</script>

body section

<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_13">Booking ID
</label>
<label class="ss-q-help" for="entry_13">To trace ur record</label>
<input type="text" name="entry.13.single" value="" class="ss-q-short" id="entry_13"></div></div></div>

the normal way to see my random number is
<input name="randomnumber" readonly> (readonly so that no one can change it)

All I required is to have this generated random number in the place of value="" so that user will not put anything but instead this random number will appear in box and go with the form submit (in the input of name=entry.13.single) because in the submit result, i can get the result whatever is in value="" place which is my requirement.


Please any one help me on this. I want this to be done by any means.

Thanks in advance

First replace the dots in the entry.13.single with '_'
Then do the same thing to entry_13_single as you did in to randomnumber in the function randomnumber()

<script type="text/javascript">
	function randomnumber() 
	{
		document.forms[0].randomnumber.value=(…
		document.forms[0].entry_13_single.value = document.forms[0].randomnumber.value
	}
	onload=randomnumber
</script>

EDIT : Hope I understood your question correctly.

Thanx Naranga for ur reply.

I would like to ask that removing (.) means removing them from name=entry.13.single or in ur script only?
I forget to mention that i cannot change the part name=entry.13.single as it is related to back-end database where i have no access. I have to do something in this page only.

BTW just for my knowledge and testing, I try ur script as

<script type="text/javascript">
function randomnumber()
{
document.forms[0].randomnumber.value=(Math.round(Math.random()*999999+1));
document.forms[0].entry_13_single.value = document.forms[0].randomnumber.value
}
onload=randomnumber
</script>

doing so bring nothing on the page on refresh. Does this go into back-end(database) only?
The number should appear on opening the page in the text box of Booking ID so that user will note it down before submitting the form for reference to his post.

On refreshing the form page, it should change randomly. on submitting this form, the same number should go to the database area.

I hope you understand my explanation. Sorry I am not good in java.

Thanx

I would like to ask that removing (.) means removing them from name=entry.13.single or in ur script only?

I was referring to name=entry.13.single.

I forget to mention that i cannot change the part name=entry.13.single...

Since you can not change it, I used getElementById since you have already given an id value to the text field.
Following code calls the randomnumber function after loading all relevant elements:

<html>
	<head>
		<script>
			function randomnumber()
			{
				document.forms[0].randomnumber.value=(Math.round(Math.random()*999999+1));
				document.getElementById("entry_13").value = document.forms[0].randomnumber.value;
			}		
		</script>
	</head>
	<body>
		<!--Your form goes here-->

		<!-- Make sure following code is the last code snippet inside the body tags -->
		<script>
			window.onload=randomnumber
		</script>
	</body>
</html>

Thanx again for your help


I did exactly as u mentioned. but it is not working. I mean I cannot see any random number in the text field Booking Id. The field still empty. This random number must appear first in this box on page opening and changes on refreshing, then after submitting will go with the form data.

Your point and explanation is right. but still its not showing the random number on the form page field. This is the key point to appear the random number in the text field box of Booking ID.

You can just help me by putting your explained code with the text field box "id=single_13" for my better understanding.

Sorry for me not understanding it quickly.. :-)

Thanx in advance

Do you have FireBug installed in your browser(FireFox)?

Do you have FireBug installed in your browser(FireFox)?

No. I don't have Firebug because I never saw it before. and I am testing on both firefox and IE.

Hi Niranga,

Thanks for assistance.

As i mentioned that I cannot change the name=entry.13.single, but when I change the <input type="text" name="entry.13.single" value="" class="ss-q-short" id="entry_13"> to id="randomnumber", it worked without any problem and when I submit my form, it will submit the with the random number present currently on the page view or refresh.

Thanx for your all help.

I posted one more post regarding "Counting shows on page numeber of time refreshed/reloaded", see if u can help me there a bit.

Thanx and bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.