Solved

How to assign JSP Variable to JavaScript

Posted on 2007-11-16
9
5,961 Views
Last Modified: 2012-08-13
Hi
i have a function like below
    function sortResults(sortOption) {
    <% if(request.getAttribute("id")!=null){
             String pId = (String)request.getAttribute("id");
       var proId= '<%=pId%>';
      }%>
    }
i am not able to assign the pid value to proId it is showing null..where as i am getting the id value
please let me whethe i am properly assign this jsp value in java script variable
0
Comment
Question by:knaren_1975
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20299014
I don't know much about jsp, but I would think this would be proper:

 function sortResults(sortOption) {

    <% if(request.getAttribute("id")!=null){

             String pId = (String)request.getAttribute("id");

       }

    %>

       var proId= '<%=pId%>';

    }

Open in new window

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20299022
Or this, depending on which part is javascript and which is jsp
function sortResults(sortOption) {

    if(request.getAttribute("id")!=null){

    <%

             String pId = (String)request.getAttribute("id");

    %>

       var proId= '<%=pId%>';

    }

    }

Open in new window

0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 20299048

function sortResults(sortOption) {

    <% if(request.getAttribute("id")!=null){

             String pId = (String)request.getAttribute("id"); 

%>

       var proId= '<%=pId%>';

  <%

    }%>

    }

Open in new window

0
 

Author Comment

by:knaren_1975
ID: 20299156
it's not working...

i am getting the request.getAttribute("id") value but i am not able to assign this value into javascript varible

i but some debug statement then i can see the value coming into this.
when i add  the code var proId= '<%=pId%>'; my jsp page itself is not opening just saying  null in this Jsp

Regards
Naren
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:contactkarthi
ID: 20299181
did u try
function sortResults(sortOption) {

    <% if(request.getAttribute("id")!=null){

             String pId = (String)request.getAttribute("id"); 

%>

       var proId= '<%=pId%>';

  <%

    }%>

    }

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20299223
function sortResults(sortOption) {
  var proId= '<%= (request.getAttribute("id")!=null)?(String)request.getAttribute("id"):"" %>';
}
0
 
LVL 11

Accepted Solution

by:
Manish earned 500 total points
ID: 20317713
Just some modification in given code.
function sortResults(sortOption) {

    <%  String pId="";
    if(request.getAttribute("id")!=null){
              pId = (String)request.getAttribute("id");
%>
       var proId= '<%=pId%>';
  <%  
   }   %>
    }
0
 

Author Closing Comment

by:knaren_1975
ID: 31409571
THx
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20712577
Did you try mine?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript waiting 14 69
c# LinkButton OnClientClick 2 34
bootstrap footer centering and expand problems 7 29
how can i select 3 0
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now