Reputation: 2724
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>
Upvotes: 0
Views: 3241
Reputation: 29424
var elem = document.getElementById("total");
elem.value = your_variable;
Example:
var Counter = 0;
var elem = document.getElementById("total"),
while(condition == true) {
// some code
Counter++;
elem.value = Counter;
}
Upvotes: 2
Reputation: 683
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
Upvotes: 1