0

I want to get variable value in hidden HTML field. My code like:

<script lang=”text/javascript”>
   Var counter;
   Loop{
     Some Code . . . . 
     Counter++;
   }//end loop
</script>

<html>
   <body>
      // some code 
      <input type “hidden” name=”total” id=”total” value=”here I want to get Counter”>
   </body>
</html>

2 Answers 2

2

1.) Get the DOM object of the element

var elem = document.getElementById("total");

2.) Set the value

elem.value = your_variable;

Example:

var Counter = 0;
var elem = document.getElementById("total"),
while(condition == true) {
    // some code
    Counter++;
    elem.value = Counter;
}
Sign up to request clarification or add additional context in comments.

1 Comment

not geting value.I want to get counter value in HTML, my JS is in the head field where counter counts the dynamically add/remove the textfields. At the end I want the exact figure of counter variable. That counter's value I want to store in the hidden field, further I can post this value to PHP.(whole story)
1

You can get the value of form field by Javascript DOM API.

<script lang=”text/javascript”>
var total = document.getElementById("total").value;

Var counter;
Loop{
Some Code . . . . 
Counter++;
}//end loop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.