473,804 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using javascript to change a HTML form value

1 New Member
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 22012
acoder
16,027 Recognized Expert Moderator MVP
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
DutchKingCobra
37 New Member
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
9897
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 field names, i.e.: PHP: echo '<input type="text" name="hat_color_'.$i.'" value="'.$currentRow.'"> <input type="text" name="favorite_food_'.$i.'" value="'.$currentRow.'">'; HTML: <input type="text" name="hat_color_0" value="brown"><input
2
3367
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 of it. Is there a simple way, using JavaScript, so that if the outside option is selected, or "checked", the multiple select field will be shaded (unusable) and if it's deselected, or "unchecked", the multiple select field will be unshaded...
2
1573
by: Kenneth | last post by:
Is there anyway to create a javascript function to submit a form in the same html file?
1
3204
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 gmail use to detect and warn "Gmail says my browser's cache is full" http://gmail.google.com/support/bin/answer.py?answer=14106 then there should be a way to do it if google can do it. Any thoughts ?
1
1365
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 in middle, heading always on top middle etc. Some buttons always on bottom left (100 px away from screen bottom) etc... How can i do this using javascript or CSS/ Thanks
2
9265
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" id=AA name=AA value="TESTA"> <Input Type="hidden" id=BB name=BB value="TESTB"> </Form> And I need a simple C# ASPX to get the TESTA, TESTB values passed from the
3
1650
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 are in the same group AB. When A is selected, C is enabled; otherwise, C is disabled. MY code is: JavaScript: function enableC(){ document.Form1.C.enabled = true; }
3
1437
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 will have to have an onselect() anyway, but apart from a better control of appearance, what other pros and cons are there? Coding it up looks a shade simpler in HTML rather than script, but thats
7
4121
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" name="song" /> song2: <input type="text" name="song" /> song3: <input type="text" name="song" /> song4: <input type="text" name="song" /> <input type="submit" value="submit" /> </form>
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.