i have a problem in passing drop down value in onchange method from jsp to javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganihskmca
    New Member
    • Feb 2010
    • 5

    i have a problem in passing drop down value in onchange method from jsp to javascript

    The error im getting is object expected.

    This is my jsp page:

    Code:
    <%@ page import="java.sql.*" %>
    <%
    String connectionURL = "jdbc:mysql://localhost/new";
    Connection connection = null;
    Statement statement;
    ResultSet rs;
    %>
    
    <html>
    <head>
    <script type="text/javascript" src="Task113.js">
    </script>
    </head>
    <body>
    
    <%
    String s=request.getParameter("q");
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(connectionURL, "root", "cng");
    statement = connection.createStatement();
    rs = statement.executeQuery("SELECT prid FROM project where pid='"+s+"'");
    String targetId=request.getParameter("q");
    %>
    
    <form name="myform1" method="post" action="Task113.jsp">
    Projects for Program are :&nbsp;&nbsp;
    <select name="project" id="project" style="width: 100px" onChange="showCustomer6('this.value')">
    
    <%
    while(rs.next())
    {
    String result=rs.getString(1);
    String home="unbounded";
    %>
    <%
    out.println(s+" consist of :<br>");
    if(targetId.equalsIgnoreCase("unbounded"))
    {%>
    <option value="<%= home %>">
    <%= home %>
    </option>
    <%}
    else if(targetId.equalsIgnoreCase("Program 1"))
    {%>
    <option value="<%= result %>">
    <%= result %>
    </option>
    <%}
    else
    {%>
    <option value="<%= result %>">
    <%= result %>
    </option>
    <%}
    }
    %>
    </select>
    
    </form>
    </body></html>


    This is my javascript page:

    Code:
    var xmlhttp
    
    function showCustomer6(str)
    {
    alert("1");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    }
    var url="dummy.jsp";
    url=url+"?q1="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
    }
    }
    
    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
    }
    Edit/Delete Message
    Last edited by Dormilich; Feb 26 '10, 01:28 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a little more detail about the error would be incredibly useful (e.g. the line number of the error)

    Comment

    • ganihskmca
      New Member
      • Feb 2010
      • 5

      #3
      line number 27.The onchange method is not calling the javacript selectCustomer6 () method.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        remove the quotation marks from this.value, otherwise it’s treated as the string "this.value ".

        Comment

        • ganihskmca
          New Member
          • Feb 2010
          • 5

          #5
          ya i removed it,now the items present in second drop down box is unavailable after selecting a particular one in those.

          Comment

          Working...