Solved

How to assign JSP Variable to JavaScript

Posted on 2007-11-16
9
5,997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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 the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

732 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