473,406 Members | 2,707 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,406 software developers and data experts.

Dynamically add value into input tag that is in the div tag

Hello everyone,
I would like to know about how to add value to input tag with javascript dynamically ,that is
Expand|Select|Wrap|Line Numbers
  1. <div id="editForm">
  2.  <input type="hidden" name="x" value="" >
  3. </div>
  4.  
  5. <script>
  6.  function addValue(){
  7.   ...
  8.  }
  9. </script>
How can i add the x value within the addValue() method.
Thanks and Regards,
Yan Paing
Jun 18 '10 #1
4 3292
Dormilich
8,658 Expert Mod 8TB
the most simple approach (probably) is:
Expand|Select|Wrap|Line Numbers
  1. function addValue()
  2. {
  3.     this.value = this.name;
  4. }
  5.  
  6. // apply the function
  7. // input being the input element
  8. addValue.call(input);
Jun 18 '10 #2
Hello Dormilich,
I don't see clearly, if the input tag in the div is more than one how will i call the function?

Expand|Select|Wrap|Line Numbers
  1.  
  2.     <script>
  3.      function addValue(status,nameOfForm){
  4.           if(status=="addAll"){
  5.           ......//add x=100 inside nameOfForm div,
  6.          }else {
  7.                ......//add x=-100 inside nameOfForm div
  8.          }
  9.      }
  10.    </script>
  11. <html>
  12.  <body>
  13.   <form name="addForm" onSubmit="addValue('addAll','editForm1')" action="b">
  14.         <div id="editForm1">
  15.      <input type="hidden" name="x" value="" >
  16.       <input type="hidden" name="y" value="" >
  17.        <input type="hidden" name="w" value="" >
  18.     </div>
  19.  
  20. </form>
  21.  
  22. <form name onSubmit="addValue('subAll','editForm2')" name="subForm" action="a">
  23.     <div id="editForm2">
  24.      <input type="hidden" name="x" value="" >
  25.       <input type="hidden" name="y" value="" >
  26.        <input type="hidden" name="w" value="" >
  27.     </div>
  28.  
  29.  
  30. </form>
  31. </body>
  32. </html>
  33.  
Thanks and Regards
Yan Paing
Jun 18 '10 #3
Dormilich
8,658 Expert Mod 8TB
what do you mean by add x=100? add the string "x=100" to the input’s value? or add 100 to the input’s current value?

unless you have a kind of url rewriting, check the forms’ action attributes, they have to point to a file.
Jun 18 '10 #4
@Dormilich
Hello Dormilich,
Thank you for reply.
i want to add string
Expand|Select|Wrap|Line Numbers
  1. "x=100"
Thanks and Regards,
Yan Paing
Jun 18 '10 #5

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

Similar topics

1
by: Peter Kirk | last post by:
Hi there I have a form which submits a list of data to a web-application (which then saves to a database). The list consists of four input fields per row. Eg....
6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
2
by: upersson | last post by:
Hi! When accessing my web page I build up the javascript and html dynamically. Depending on an parameter I want to set all the fields (input tags) readonly. How do I do this? Of course I can...
2
by: crjunk | last post by:
I'm trying to find a way to create input boxes dynamically on the client side but everything that I've come across works with IE, but not FireFox. On my web page, I have the following input...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: Steve2007 | last post by:
Hi I have the following form in my html page: <form name="mapserv" method=GET action=""> <input type="hidden" name="timeFiltering"> <input type="hidden" name="filteringType"> <input...
2
by: Ed Jay | last post by:
I'm dynamically creating several form input elements: mValue = integer constant; for(var j = 0; j < mValue; j++) { target = "imgCn"+ j; eName = "myFile"; eName = eName+jj;...
1
by: Appu2008 | last post by:
Hi, Iam trying to invoke a javascript calendar in the click event of an input box. The input box is an array created dynamically. But the clicking does not works correct. I think the problem...
3
by: sangx001 | last post by:
Hi everyone, So I've got a form that I want to submit using the GET method. In the form you can dynamically add <input type=text/> fields to the form via javascript. The problem is that to new...
4
by: mfaisalwarraich | last post by:
Hi everybody, I have some problem so need some help. wat im trying to do is making a function which will change the value of a input field when the value of other input field is changed. im using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.