Entry
How to compare 'JavaScript' variable with a 'Java' Variable in JSP??
javascript variable in JSP
for(i=0;i < <%=objUser.length%> ;i++) if(usrId == "<%=((User)objUser[i]).getUserID()%>") the variab
How to pass javascript var into jsp block and assign to jsp variable?
pass javascript variable into jsp block and assign to jsp variable. <script language="JavaScript">
How to pass javascript var into jsp block and assign to jsp variable?
Apr 5th, 2008 20:35
ha mo, kAt v, Francesco Defazio, Nataraj Vankadara, Srini Vasan, Sandy Shan, sujana pvl, Francesco Defazio
It is possible indirectly.
You can copy the value of jsp variable in html hidden field.
And now in javascript you can read the value of this field and compare
it with javascript variable.
ex.
<form name="form1">
<input type="hidden" name="field" value="<%=your_jsp_variable%>">
</form>
in javascript you read in this way
<script language="javascript">
var my_javascripts_variable;
function compareVariable(){
if ( my_javascripts_variable == document.form1.field.value ){
.....
.....
}
}
</script>
You can insert the function compareVariable for example in the OnLoad
event of Body.
------------------------------
On most browsers, you can use JSP <%= %> tags directly inside
javascript tags. The only catch is that you'll be getting the String
value of your jsp variable (so no, you can't compare arrays, or any
other complex objects).
ex.
<script langauge="javascript">
function compareVariable() {
if ( my_javascript_variable == <%=jsp_variable%> ) {
....
....
}
}
</script>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com