Computing.Net > Forums > Programming > jsp variable in java script

jsp variable in java script

Reply to Message Icon

Original Message
Name: mythri
Date: May 5, 2004 at 04:35:06 Pacific
Subject: jsp variable in java script
OS: windows xp
CPU/Ram: p 3 128 ram
Comment:

Hi,
iam trying to use the variable declared in jsp tags in the scipt.
both exists in the same jsp page.
I need to access the jsp variable in script function,where that jsp variable contain the data accessed from the database.
its urgent plz

kowsalya


Report Offensive Message For Removal

Response Number 1
Name: Don Arnett
Date: May 5, 2004 at 06:00:14 Pacific
Subject: jsp variable in java script
Reply: (edit)

Use the = jsp tag to display the value of the jsp variable and make it part of the javascript code. Replace the brackets below with < and >.

My JSP book is not handy, but it should look something like this:


var name;
name="[%= jspName ]";


Report Offensive Follow Up For Removal

Response Number 2
Name: gpp
Date: May 5, 2004 at 15:18:56 Pacific
Subject: jsp variable in java script
Reply: (edit)

Dont forget the % sign on the closing bracket as well..


Report Offensive Follow Up For Removal

Response Number 3
Name: mythri
Date: May 5, 2004 at 22:10:16 Pacific
Subject: jsp variable in java script
Reply: (edit)

Hi,
I tried with 2 stmts wt u mentioned above but it is not working.
nothing is being displayed on the browser.but in the status bar it is giving like "done with some errors on the page"

iam giving the code .


<%String name="something";%>
<script>
window.alert("hello");
var x="<%=name%>";
window.alert("hai"+x);
</script>


iam able to get the first alert box
but not the second alert box.

IT IS URGENT HELP PLZ..

kowsalya


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: jsp variable in java script

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software