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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koyanpaing
    New Member
    • Mar 2010
    • 26

    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
    Code:
    <div id="editForm">
     <input type="hidden" name="x" value="" >
    </div>
    
    <script>
     function addValue(){
      ...
     }
    </script>
    How can i add the x value within the addValue() method.
    Thanks and Regards,
    Yan Paing
    Last edited by Dormilich; Jun 18 '10, 08:37 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the most simple approach (probably) is:
    Code:
    function addValue()
    {
        this.value = this.name;
    }
    
    // apply the function
    // [I]input[/I] being the input element
    addValue.call([I]input[/I]);

    Comment

    • koyanpaing
      New Member
      • Mar 2010
      • 26

      #3
      Hello Dormilich,
      I don't see clearly, if the input tag in the div is more than one how will i call the function?

      Code:
           
          <script>
           function addValue(status,nameOfForm){
                if(status=="addAll"){
                ......//add x=100 inside nameOfForm div,
               }else {
                     ......//add x=-100 inside nameOfForm div
               }
           }
         </script>
      <html>
       <body>
        <form name="addForm" onSubmit="addValue('addAll','editForm1')" action="b">
              <div id="editForm1">
           <input type="hidden" name="x" value="" >
            <input type="hidden" name="y" value="" >
             <input type="hidden" name="w" value="" >
          </div>
      
      </form>
      
      <form name onSubmit="addValue('subAll','editForm2')" name="subForm" action="a">
          <div id="editForm2">
           <input type="hidden" name="x" value="" >
            <input type="hidden" name="y" value="" >
             <input type="hidden" name="w" value="" >
          </div>
      
      
      </form>
      </body>
      </html>
      Thanks and Regards
      Yan Paing

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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.

        Comment

        • koyanpaing
          New Member
          • Mar 2010
          • 26

          #5
          Originally posted by Dormilich
          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.
          Hello Dormilich,
          Thank you for reply.
          i want to add string
          Code:
          "x=100"
          Thanks and Regards,
          Yan Paing

          Comment

          Working...