element id is not accessible javascript -
i have following code. here declaring element id's variables global before functions declared. variables taken functions below sample:
var ddlpf=document.getelementbyid('<%=ddlpf.clientid%>'); var disp_msg=document.getelementbyid('<%=disp_msg.clientid%>'); function btn_proceed_click() { var ses='<%=session("hcur").tostring %>'; if(pos_valid()==true) alert('success'); } function pos_valid() { var pos_valid=false; var ses; var ccy; var ccy1; var ccy2; var as11costbud; ses='<%=session("hcur").tostring %>'; var bm='<%=session("benchmark").tostring %>'; var dtsheet='<%=session("dtsheet").tostring %>'; var ratedis='<%=session("ratedis").tostring %>'; if(ddlpf.selectedindex <= 0) { message("please select portfolio"); return; } pos_valid=true; return pos_valid;
}
function message(msg) { disp_msg.innerhtml=msg; var modalpopupbehaviorctrl = $find('modalpop'); modalpopupbehaviorctrl.set_popupcontrolid("poppan"); modalpopupbehaviorctrl.show(); }
if declare variable "ddlpf" inside pos_valid() , "disp_masg" inside message(), works. code this:
function pos_valid() { var ddlpf=document.getelementbyid('<%=ddlpf.clientid%>'); //code } function message() { var disp_msg=document.getelementbyid('<%=disp_msg.clientid%>'); //code }
but these id's common 5 functions. not two. have 20 id's common 5 big functions. thats why have declared them outside functions.
what change should make?
i guessing putting script @ top of html page. page has not finished loading yet , trying access document.getelementbyid
before document.body ready. when access them in functions, variables value undefined
=> problem
try way,
var ddlpf; var disp_msg; window.onload = function(){ ddlpf=document.getelementbyid('<%=ddlpf.clientid%>'); disp_msg=document.getelementbyid('<%=disp_msg.clientid%>'); }
this way, can put code anywhere.
Comments
Post a Comment