简体   繁体   中英

how to get HiddenField value in separate javascript file [asp.net]

from aspx file

HiddenField ID="HiddenField1" value="1"

this is Charting.js (external JS)

var b = $("#" + '<%=HiddenField1.ClientID%>').val();//im not really sure with this

alert(b);//(to test if it work
if (b == "1")
{
    $("#" + a).attr({
        "font-weight": 900
    });

}

usually if i do script inside aspx in 1 page i just use

HiddenField1.ClientID

can anyone help me?

Its not necessary that you need to select by id only. You can set a value to class attribute of hidden field and use it to select in js file as following.

<input type="hidden" class="myclass" value="myvalue"/>
var b = $(".myclass').val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM