473,408 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Using javascript to change a HTML form value

Hi guys,

I don't know whether this is a HTML or Javascript question, but i decided to put it here.

This is my problem:

I am making a simple HTML form that posts a random number (generated by Javascript) on my website, but I'm having trouble assigning the random number to the form.

This is what I have right now:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. <html>
  5.  
  6. <head>
  7.  
  8. <title>xxx</title>
  9.  
  10. <script type="text/javascript">
  11.  
  12. function changejweet()
  13. {
  14.  
  15. document.reply.topic.value = "***RANDOM NUMBER***";
  16. document.reply.action = "http://site.com/post_reply/" +***RANDOM NUMBER***";
  17.  
  18. }
  19.  
  20.  
  21. function randomnumber() 
  22. {
  23.     document.getElementById("rand").value = Math.round((1000000 - 500000) * Math.random() + 1);
  24. }
  25.  
  26. </script>
  27.  
  28. </head>
  29.  
  30. <body onload=changejweet();>
  31.  
  32. <form name="reply" action="site.com/post_reply/" method="post">
  33.  
  34. <input type="hidden" name="topic" value="1">
  35. <input type="hidden" name="skipVerbose" value="TRUE">
  36. <input type="submit" name="submit" value="Click to send random number">
  37.  
  38. </form>
  39.  
  40. </body>
  41.  
  42. </html>
  43.  
The ***RANDOM NUMBER*** is the values that I want to change into the random number.
I already tried:
Expand|Select|Wrap|Line Numbers
  1. document.reply.topic.value = rand;
  2. document.reply.action = "http://site.dom/post_reply/" + rand;
But that didnt work.


I am a javascript/HTML beginner and would like to know how to do this.

Can someone help me?

Thanks in advance !

MCV
Apr 5 '07 #1
2 21985
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

You don't have an element with id "rand". Declare a variable, rand, and set that to the random number:
Expand|Select|Wrap|Line Numbers
  1. var rand = ...Math.random...etc.
then use that to set the form value.
Apr 5 '07 #2
Hi pal,
here you are:)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>xxx</title>
  4.  
  5. <script type="text/javascript">
  6. function randomnumber(){
  7. randomnr=[Math.floor(Math.random()*10000000000)];
  8. document.reply.rand.value = randomnr;
  9. document.reply.topic.value = "***RANDOM NUMBER***";
  10. document.reply.action = "http://site.com/post_reply/" + randomnr;
  11. }
  12. </script>
  13. </head>
  14. <body>
  15.  
  16. <form name="reply" action="site.com/post_reply/" method="post" onsubmit="randomnumber()">
  17. <input type="hidden" name="topic" value="1">
  18. <input type="hidden" name="rand" value="random number">
  19. <input type="hidden" name="skipVerbose" value="TRUE">
  20. <input type="submit" name="submit" value="Click to send random number">
  21. </form>
  22.  
  23. </body>
  24. </html>
  25.  
well HTH
peace
Apr 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jason | last post by:
Currently I have a number of html forms which loop through records in a database table. In order to be able to update the right record when the form is submitted, I've tacked number on to the...
2
by: Mike N. | last post by:
I am looking to use an HTML checkbox feature as a trigger to shade/unshade a multiple select field in an HTML form. For instance: there are four options in the multiple select field and one outside...
2
by: Kenneth | last post by:
Is there anyway to create a javascript function to submit a form in the same html file?
1
by: onewebclick | last post by:
Is there a way to detect a browser cache is full using javascript or HTML thorugh a web page and inform the user to clear the cache to improve performance of the website. It looks like google's...
1
by: keerthana_m_2003 | last post by:
Hello: I am designing a web page where there are some buttons text etc. I want to design it in such a way that, irrespective of the screen size, resolutoin; the buttons will have to come always...
2
by: leonlien | last post by:
I am learning C# now .. so please bear with me if I don't make any sense. I have a plain HTML form on WEB Server 1 <Form action ="ABC.aspx" method=POST id=fURL name=fURL> <Input Type="hidden"...
3
by: david | last post by:
I have written JavaScript and try to change the radio button property (disenable other radio buttons) once click on it. But it does not work. For example, I have radio buttons A, B, and C. A and B...
3
by: The Natural Philosopher | last post by:
Ok, I have another form to write, and one of its features will be pop up or drop down select-from-list stuff. Could be done with javascript, could be done with <SELECT> <OPTIONetc etc.. It...
7
by: yuki007 | last post by:
I need to know how to add many datas into a table using html form and the php query for example, i want to do like this <form action="addsong.php" method="post"> song1: <input type="text"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.