0

I am trying to make a website using JSP. In the onload event, a JavaScript function should run, in the JSP template for the function, I use an if condition. The goal is to check for a URL parameter and only actually run a function when that parameter is found.

Here is my code:

<script language="javascript">

function raj(){

 <%if (String "contact"=request.getParameter("contact");) %>{


    <% String str=request.getParameter("video"); %>
    var s="<%=str%>";
    alert(s);
    }
}
</script> 

What went wrong, and how can I fix it?

1
  • 1
    Though I don't know JSP (Only javascript and other programming language), as a programmer I think there should not be a semi colom after ("contact")<here> Commented Oct 19, 2014 at 13:01

1 Answer 1

0

You can't create a variable in if statement. First create a variable then initialize and check it. Don't forget to close if block with }.

<script language="javascript">

function raj(){   
 <%String contact; if ((contact=request.getParameter("contact")) != null) %>{    
    <% String str=request.getParameter("video"); %>
    var s="<%=str%>";
    alert(s);
 <%}%>
}

</script> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.