Passing Parameter from javascript to Servlet

hi,
I have 2 list boxes in my Jsp page and values for these list boxes are preloaded . These things are to be carried out using javascript onload() function.
So now i want to pass the selected parameters from both the list boxes to servlet and have to display the corresponding resulting datas in same JSP page. if i submit the form then values selelcted by the user will reset because the form has onload() function. then i thought hidden field will solve my problem. but its giving error like nullpointer exception.
so please tell me how to achive this.

When you right a new Option(...) line in javascript, there are three parameters you can give:
Option("text", "value", selected);
How you make use of this depends on how you move from the servlet back to the JSP.
So for example, if you are doing a response.sendRedirect in the servlet, you will either have to add a parameter back to the url you are re-directing to, or add the value to the session. (I like the session method myself... hides it from the user)
//in servlet
  public void doGet(...)... {
    String country = request.getParameter("country");
    String state = request.getParameter("state");
    //... Do Stuff ...
    HttpSession session session = request.getSession();
    session.setAttribute("country", country);
    session.setAttribute("state", state);
    String sendTo = response.encodeRedirectURL("theForm.jsp");
    response.sendRedirect(sendTo);
  //... The JSP might look like this now...
  //Get the selected values from the session:
  <%
    String countrySelected = (String)session.getAttribute("country");
    String stateSelected = (String)session.getAttribute("state");
  %>
  <html>
  <head>
  <script type="text/javascript">
  /* Use this to store the values for states in JavaScript */
  var state2DArray;
  /* Javascript function to set up values for the states  and countries */
  function initSelects() {
    <%
      /* This is JSP scriptlet code to get the country list that we need... */
      List countries = (List)application.getAttribute("countryList");
    %>
    countrySelect = document.form.country;
    <%
      /* This is JSP scriptlet code to loop through the countries and assign
       * values as needed.  We will break out of scriptlets to print out
       * the javascript needed to assign values to the countrySelect and to
       * the state2DArray
      int countryCount = countries.size();
    %>
    state2DArray=new Array(<%=countryCount+1%>);
      state2DArray[0] = new Array(1);
      state2DArray[0][0]="--Select A State--";
    <%
      for (int co = 1; co <= countryCount; co++) {
        Country country = (Country)countries.get(co-1);
        List stateList = country.getStates();
        int stateCount = stateList.size();
    %>
    //Now we add a true/false if the country should be selected...
    countrySelect.options[<%=co%>] = new Option("<%=country.getName()%>","<%=country.getId()%>",
                                                <%= (country.getId() == countrySelected)%>);
    state2DArray[<%=co%>] = new Array(<%=stateCount+1%>);
    state2DArray[<%=co%>][0] = "--Select A State--";
    <%
        for (int st = 1; st <= stateCount; st++) {
          String stateName = (String)stateList.get(st-1);
    %>
    state2DArray[<%=co%>][<%=st%>] = "<%=stateName%>";
    //We are going to call the fillInStates now at the end of initSelects so the initial
    //values are passed on to the states...
    fillInStates(countrySelect);
    <%
    %>
  function fillInStates(countrySelect) {
    selectedCountry = countrySelect.selectedIndex;
    stateCount = state2DArray[selectedCountry].length;
    stateSelect = document.form.state;
    stateSelect.options.length = 0;
    for (state = 0; state < stateCount; state++) {
      //Again add true/false if it should be selected...
      stateSelect.options[state] = new Option(state2DArray[selectedCountry][state], state2DArray[selectedCountry][state],
                                              <%= (stateSelected == state2DArray[selectedCountry][state]) %>);
</script>
  </head>
  <body onload="initSelects()">
  <form name="form" id="form" action="#" method="get">
    <select name="country" id="country" onchange="fillInStates(this);">
      <option value="">--Select A Country--</option>
    </select>
    <select name="state" id="state">
      <option value="">--Select a State--</option>
    </select>
  </form>
  </body>
</html>

Similar Messages

  • Passing variable from javascript to servlet!!!

    Hi all,
    I have one doubt,
    can we pass a variable from javascript to servlet???
    In Brief,
    i am getting some values in javascript through jsp and the same values i
    want to use in servlet.
    Yes, i know i can get these values in servlet by using request.getParameter("");
    But these values are dynamically generated so i dont know how many varaible are they!. so i am trying to put some array list so that i can forward this values to servlet.
    But i can't get this array which is declared in javascript!! :( so any buddy can help me how to get this dynamically generated values in servlet!!!
    Thanks in Advance!! :)

    can you post a sample of your code?
    remember to put it between tags                                                                                                                                                                                       

  • Pass parameter from javascript to backing method

    Hello professional ,
    i have an ADF (JSF page) there is news bar on it when the user click on any news link i want to pass the news parameter to backing method .
    The problem is how can i pass javascript value to commandLink jsf tags to setActionListener sub Tags:
    <tr:commandLink id="openNewsActionLink"
    text="#{screenLabels.NEWS_DETAILS}"
    inlineStyle="display:none; visibility: hidden;"
    action="#{publishedNewsBackedBean.openNewsDeatilsAction}">
    <tr:setActionListener from="6"
    to="#{publishedNewsBackedBean.selectedID}"/>
    </tr:commandLink>
    i want to pass the from value from java script code how can i do it and if i can not do it directly what is the work around for it.
    Regards
    Mohd79

    Hi,
    assign an ID to the inputText and use the JavaScript Document Object Model to access it. Also use a good browser with good DOM source viewer to browse the HTML page your JSP creates at runtime Firefox and Chrome have good source viewers.
    there are truckloads of JavaScript examples on the Internet.
    Or as Frank said if you get the setActionListener working properly you can easily copy a value from one input value binding to another.
    Brenden

  • How to pass parameter from javascript to applet ?

    i have some parameters from form in html,
    and i would like to pass from javascript to an applet,
    (which a type of calling method in applet from javascript)
    and get back data from applet to display in html
    how could i do this ?

    in my program,
    i pass 3 string to the applet
    var reply = document.test.called(ft, fc, tc)
    in the fucntion "called" in the "test" applet
    i simply test it by
    public String called(String l, String from, String to){
    return "abcd";
    but the result should the value return is "1"
    can anyone help me ?

  • Passing value from javascript function to servlet

    Hello everybody,
    i need to pass parameter from javascript function to servlet.
    what i wrote is :
    function callPopulateServlet(t)
    var h =document.NewRequest.services;
    var y = t.selectedIndex;
    alert(h.options[y].value);
    var id=h.options[y].value;
    <%session.setAttribute("id",id);%> // am getting error at this point
    document.NewRequest.submit();
    with this id am quering values from database through servlet.
    any body knows plz help me.
    thanks,
    anil.

    this is the error am getting
    Stacktrace:
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

  • Can't pass parameter from HTML form of multipart/form-dta type to JSP

    I am using request.getParameter(passed variable name) to pass data from HTML form to JSP with no problem. WHen I try to pass data from HTML form of multipart/form-dta type to JSP as following:
    < form enctype="multipart/form-data" name="theForm" method="post" ACTION="http://titan.ssd.loral.com:7778/ifs/jsp-bin/ifs-cts/stringsecond.jsp">
    The passed value is null. Why?
    How can I pass data successfully from this form to JSP?
    How can I pass data from JavaScript to JSP?
    Thank you

    I am using request.getParameter(passed variable name)
    to pass data from HTML form to JSP with no problem.
    WHen I try to pass data from HTML form of
    multipart/form-dta type to JSP as following:
    < form enctype="multipart/form-data" name="theForm"
    method="post"
    ACTION="http://titan.ssd.loral.com:7778/ifs/jsp-bin/if
    -cts/stringsecond.jsp">
    The passed value is null. Why?because the jsp most likely does not handling of POST parameters like this.
    How can I pass data successfully from this form to
    JSP?jsp's are not meant to read such amounts of data. this (= uploading) is a typical task for a specialized servlet. there you have full control over input and output. if you need to, you can still forward to a jsp after processing in the servlet.
    How can I pass data from JavaScript to JSP???? i'm not sure what exactly you mean. normally you put it into an url and submit it.
    robert

  • How to pass parameter from 1 stored procedure to another stored procedure inside crystal report

    Hi
    I have several stored procedure in my Crystal Report. I am wondering if it is possible for me to pass a parameter to one of the stored procedure and to use the result of that stored procedure E.g. CustomerCode. To another 2 stored procedure to generate the report dynamically?
    I have 3 stored procedure
    The 1st one is used to gather information and process the calculation
    another 2 stored procedure is used for generate the graph and both of them required to take 2 parameters. The 1st stored procedure will require 1 parameter (E.G. Reference Code) and will return a set of information including the data that could be use on the other 2 stored procedures.
    After I added these 2 stored procedure, it requires me to pass 3 parameters to the report. I would like to know if I could only pass the Reference Code for stored procedure 1 and use it to retrieve the information for the other 2 parameter?
    Thanks in advance
    Chi

    Hi Chi
    To pass parameter from 1 stored procedure to another stored procedure, you will have to create sub report. In your case you will have to create 2 sub reports for 2nd and 3rd stored procedure and link those sub reports with the main report using Reference Code field in order to pass the values.
    After creating the report when you will refresh the report, it will ask 4 parameters, one parameter for main report, one for the first subreport and two for second subreport to fetch the data correctly.
    Regards
    Poonam Thorat.

  • How to pass parameter from form6i to report6i

    when i passed parameter from form6i to report6i, while previewing report the data was not displaying only fields heading was displaying, but in report6i there is a parameter form thru that it was displaying data, but thru form6i to report6i it was not. Please kindly help me and give me the some sample or example of it.
    Thanks
    Best regards
    Zaheer

    ADD_PARAMETER(pl_id,'P_SCRIPT',TEXT_PARAMETER,:b1.script);

  • Master-detail relationship - passing parameter from form to form

    Hello.
    I have a question about master detail relationship.
    In first form we have master-detail relationship.
    Example on dept, emp tables:
    We query dept (master), so we can get one or many emp (detail) records. Then we have a third table - tasks. Tasks table (detail) can have many records for one employee.
    Tasks table is in another form, which is called with call_form built_in. So we pass a parameter from master to detail - parameter empno. Because of that, we can only see tasks for one employee and can't navigate to another employee. This is normal.
    Now comes the question.
    Is it possible to call a form (with tasks table) with deptno parameter (so we can navigate through all employees with that department), but first show employee that was last used in first form?
    Example of our goal.
    Master: deptno = 20
    Detail: navigate to JONES employee
    Call new form (tasks)
    Tasks for JONES employee are first shown
    Can navigate to another employee - without requery
    Is this possible?
    If we pass deptno parameter, we can navigate through all employees - but must navigate to the employee we last used in first form.
    If we pass empno parameter to second form, we see last used employee but cannot navigate to another employee without requery.
    Hope you understand my problem.
    Thanks.

    Hi
    yes you can pass parameter from one form to another.
    In your master detail form set the trigger when-new-instance and there define the global variable like
    :GLOBAL.G_CIRCLE_ID := NULL;
    and in your task table set the trigger when-new-instance and there define the global variable like and also write this code
    :GLOBAL.G_DIVISION_ID := NULL;
    IF :GLOBAL.G_CIRCLE_ID IS NOT NULL THEN
         GO_BLOCK('DIVISION');
         SET_BLOCK_PROPERTY('DIVISION',DEFAULT_WHERE,'CIRCLE_ID ='||''''||:GLOBAL.G_CIRCLE_ID||'''');
         EXECUTE_QUERY;
    END IF;
    :GLOBAL.G_CIRCLE_ID := NULL;
    now you maintain your trigger according your need.
    Regards,

  • Problem while passing parameter from report to report.

    Hi
    I'm using forms and reports 10g, hava a problem while passing the parameter from reports to report.
    i'm using srw.set_hyperlink to call report from report.
    i have created a key value in the cgicmd.dat file called
    faccre802005-2006: report=faccre80 destype=cache desformat=pdf userid=<userid/passwd@cs> server=<servername>
    Now in the format trigger i'm using this key value
    function BTN_DEBITFormatTrigger return boolean is
    temp varchar2(5000);
    IP_ADDRESS VARCHAR2(50);
    SERVER_NAME VARCHAR2(10);
    L_ACCT_CODE VARCHAR2(14);
    begin
    SELECT MAST_INT_DESC,MAST_USER_PGM_ID INTO IP_ADDRESS,SERVER_NAME FROM MAST_INT_INFO WHERE MAST_INT_ID='VISHWA';
    temp := IP_ADDRESS||'?faccre80'||:P_FIN_YEAR||'+server='||server_name;
    temp :=temp ||'+'||'P_PREVIOUS_CODE='''||:ACCT_CODE||''''||'+'||'P_COMPANY_CODE='''||:P_COMPANY_CODE||'''';
    temp :=temp ||'+'|| 'P_FROM_DATE='''||TO_CHAR(:P_FROM_DATE,'DD-MON-RRRR')||''''||'+'|| 'P_TO_DATE='''||TO_CHAR(:P_TO_DATE,'DD-MON-RRRR')||''''||'+'||'P_TRUST_CODE='''|| :P_TRUST_CODE||'''';
    temp :=temp ||'+'|| 'P_UNIT_CODE='''||:P_UNIT_CODE||''''||'+'||' P_FIN_YEAR='''||:P_FIN_YEAR||'''';
    temp :=temp ||'+'|| 'P_LEVEL='''||:P_LEVEL||''''||'+'||'P_HEADER='''||replace(:P_HEADER,' ','%20')||''''||'+'||'P_FORMAT='''||:P_FORMAT||'''';
    SRW.Set_Hyperlink(temp);
    END;
    return (TRUE);
    end;
    Report is coming but not the expected result because parmaeters are not coming from first report to second report.
    If i dont use cgicmd file userid and password are displyed in the URL.
    Pl tell me how to pass parameter from one report to another.
    thanks and regards

    Hi
    I got the solution.
    I forgot to add %* at end of the KEY value.

  • How can I pass parameter from report to form?

    Hi :)
    Now I try to build conference room like this by using form
    and report. And i design that when users click at group report
    then i'll show page that contain questions report and add
    question form. And question form and report must receive the
    same parameter from group report.
    First Problem: is I don't know how group report send the
    same parameter to question report and add question report at the
    same time. And is it possible??? If not please suggest me what
    should I do???
    Second Problem: is I don't know how can I pass parameter from
    report to form. I don't know the way to do it.
    Please tell me!!! Please...
    I look forward to hearing from all of you.
    Thank You.

    One way is to create a link based on that form and attach that
    link with the report. Through links you can pass parameters

  • How to   Pass Parameter from BIP  to Dashboard  Report

    Hi,
    Parameter from BIP to Dashboard Report
    If I select BIP report paremeter should pass value to dashboard report
    thanks in advance.
    CHEERS ,
    Jel

    Hi Saichand,
    I hav gone through above link its passing values from Dashboard prompt to BIP report only..
    just i need like reverse (if i click on BIP report value then it should pass that value to Dashboard reports) in this this case how to pass parameter from BIP to dashboard report
    Thanks in advance
    Cheers,
    Jel

  • Hw to pass parameter from report to forms

    Dear Friends,
    I m working on Forms n Reports 6i,
    I m running report n passing parameter from the forms now the requirement is that if report run successfully it shuld give the msg otherwise give an user define error msg.
    Hw do i pass any parameter from report to form for acknowledgment.
    Thanking yours
    Chandan

    Hi Rajat,
    using run_product built in i can pass parameter from forms to reports but hw can i get some parameter value from reports to forms as mentioned earlier my post
    Thanking Yours,
    Chandan

  • Passing data from JAVASCRIPT to SAP database

    Hi Experts,
    Is it possible to connect or access RFC function module through JAVASCRIPT? I want to send data from JAVASCRIPT to SAP database table.
    Is it possible to pass data from JAVASCRIPT to SAP database table?
    Thanks in advance.
    Regards,
    Arindam Samanta.

    OData services can be one option to achieve this.
    Another possibility can be use of Generic REST enablement with SAP NetWeaver Gateway.
    If you are not considering Gateway at all, then  A JSON adapter like the one mentioned in JSON Adapter for ABAP Function Modules can be handy.

  • Passing Parameter from URL to Web Forms - Oracle 10 Application Server

    Hi All -
    I want to pass parameter from a URL to 10g Oracle Web Forms - Oracle Application Server 10.1.2
    http://server1/forms/frmservlet?config=SATWEB_SSO&otherparams=username_sso=BABUS
    How to receive this 'username_sso' value inside my forms application ?
    Created a Parameter in the same name as URL parameter 'username_sso' in forms but didn't receive the value. I want to know how to receive the value of this parameter within forms from URL.
    Thanks - Suresh

    Try this,
    1. Create a parameter in the formsweb.cfg (say username_sso) under default section ( or you can create it in your own config section)
    2. Add the username_sso in otherparams parameter as username_sso=%username_sso%
    3. Add this username_sso parameter in your form.
    4. Run the form as
    http://<machine>:<port>.....?form=blahblah....&otherparams=username_sso=scott
    Regards,
    Arun

Maybe you are looking for