Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  101] [ 1]  / answers: 1 / hits: 15512  / 15 Years ago, fri, september 18, 2009, 12:00:00

I'm trying to use the value of an asp:HiddenField control in javascript after postback and pageload.I tried something like this but it does not work.(the get function works fine but I cant seem to make hidVal get the value from the asp:HiddenFIeld)



<script type=text/javascript language=javascript>

var hidVal=document.getElementById(<% =hidField.ClientID %>).value;

function Get(checbox)
{

if(checbox.checked)hidVal += 1;
else hidVal -= 1;


document.getElementById(<% =hidField.ClientID %>).value = hidVal.toString();

}




Basicly I'm trying to get the value of a hidden field , increment it on every checked checkbox(using javascript) and reasign the incremented value to the hidden field on every postback.
If you have any idea on how to make this work please help.



Thanks for the time.


More From » asp.net

 Answers
73

remember to put the javascript part before the closing tag so when it get's there, the HiddenField is already rendered and can usable.



and, for CMS answer, do not forget to use:



<asp:CheckBox ID=chk runat=server onclick=Get(); />

[#98665] Tuesday, September 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
louiseb

Total Points: 368
Total Questions: 107
Total Answers: 107

Location: Tanzania
Member since Wed, Feb 24, 2021
3 Years ago
;