Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compare jsp variable and javascript variable

 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I campare a variable from jsp with one from javascript?

Example my javascript is declared as below

var thedate = document.frm.trxdate.value

I also have jsp variable <%= date1%>

Can i just do it like this in javascript
if (thedate < <%= date1%> {
...
}

or maybe declare the jsp variable into javascript variable first
var str=<%= date1%>

Or maybe there is another way
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't directly compare a variable in a serverside jsp with a piece of clientside code. However, as you've spotted, you can write out the value of the variable in the jsp to your html page and compare the values in JavaScript once the page has rendered. So either way you suggest in your example JavaScript will work fine. For the ins and out of which is better, you'll get a fuller answer from someone in the JavaScript forum. My two-cents: I'd always asign the value explicitly to a variable before I used it - but thats just personal preference to keep the JavaScript more readable.
 
repaka
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
declare one hidden value like this and make use of that value in your java script.
try like this:
<input type=hidden name=date value=<%=logId %> >
in your javascript use
if (thedate < document.forms[0].date.value) {
...
}
hope this solve your problem
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to make it a hidden form element unless it is to submitted in a subsequent operation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!