Results 1 to 10 of 10

Thread: First JSP page

  1. #1
    pawanjoshi is offline Member
    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Default First JSP page

    <html>
    <head>
    <title>FIrst JSP Page</title>
    </head>
    <body>
    <script>
    function setSelectedValue(val)
    {
    alert("called");
    var x=document.getElementById("PackId");

    for(i=0;i<x.length;i++)
    {
    if(x.option[i].text===val)
    x.selectedIndex=i;
    }
    }
    </script>
    <div id="logo" style="margin-left: 250px;margin-top: 50px;margin-bottom: 50px;color:#6666ff">
    <h1>
    UMM SMS Configuration
    </h1>
    </div>
    <% String PACK=(String)session.getAttribute("PACK");%>
    <form action="process.jsp" method="post">
    <table>
    <tr><td style="color:navy;"><B></B></td></tr>
    <tr><td><br></td></tr>
    <tr><td>PackId</td><td>
    <select id="PackId" name="PackId">
    <option>Select a PackId</option>
    <option>DEFAULT</option>
    <option>EAUC</option>
    <option>EAUCSONG0</option>
    </select></td></tr>

    <tr><td>Circle</td><td>
    <select id="Circle" name="Circle">
    <option>Select a Circle</option>
    <option>UPE</option>
    <option>RW</option>
    <option>BH</option>
    </select></td></tr>

    <tr><td>Action</td><td>
    <select id="Action" name="Action">
    <option>Select an Action</option>
    <option>act_success</option>
    <option>dct_success</option>
    <option>act_fail</option>
    <option>dct_fail</option>
    </select></td></tr>

    <tr><td><br></td></tr>
    </table>

    <input type="submit" value="Submit" onclick="setSelectedValue('<%=PACK%>')">
    </form>
    <br>

    <%
    if(session.getAttribute("PACK")!=null&&session.get Attribute("CIR")!=null&&session.getAttribute("ACT" )!=null){
    String SMtxt=(String)request.getAttribute("SM");
    String ident=(String)request.getAttribute("IDE");

    %>
    <form action="CreateUpdate.jsp" method="post">
    Id:<input type="text" name="Identifier" value="<%=ident%>" maxlength="5" size="5" style="margin-left: 67px;">
    <br>
    SMS_TEXT:<input type="text" name="SMSTXT" value="<%=SMtxt%>" maxlength="50" size="50">
    <br>
    <input type="submit" value="update">
    </form>
    <%
    }
    else{out.println("Drop Down values are blanks");}
    if(request.getAttribute("Upd")!=null)
    {
    out.print("<font size='10' color='black' m>");
    //out.println("Data Updated");
    out.println("</font>");
    %>
    <script>
    alert("Data Updated");
    </script>
    <%
    }
    %>
    </body>
    </html>



    Here I am trying to retain the value of drop down list using onclick event on submit button with the help of setSelectedValue() javascript but it is not working....pls suggest as i am new to HTML and jav

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: First JSP page

    Please post your code inside [code] tags [/code] so it retains its formatting.

    What does "it is not working" mean?
    From what I can see, on clicking the submit button you simply call setSelectedValue with a constant value (as far as the page is concerned).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    pawanjoshi is offline Member
    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Default Re: First JSP page

    Java Code:
    <html>
     <head>
     <title>FIrst JSP Page</title>
     </head>
     <body>
     <script>
     function setSelectedValue(val)
     {
     alert("called");
     var x=document.getElementById("PackId");
     
    for(i=0;i<x.length;i++)
     {
     if(x.option[i].text===val)
     x.selectedIndex=i;
     }
     }
     </script>
     <div id="logo" style="margin-left: 250px;margin-top: 50px;margin-bottom: 50px;color:#6666ff">
     <h1>
     UMM SMS Configuration
     </h1>
     </div>
     <% String PACK=(String)session.getAttribute("PACK");%>
     <form action="process.jsp" method="post">
     <table>
     <tr><td style="color:navy;"><B></B></td></tr>
     <tr><td><br></td></tr>
     <tr><td>PackId</td><td>
     <select id="PackId" name="PackId">
     <option>Select a PackId</option>
     <option>DEFAULT</option>
     <option>EAUC</option>
     <option>EAUCSONG0</option>
     </select></td></tr>
     
    <tr><td>Circle</td><td>
     <select id="Circle" name="Circle">
     <option>Select a Circle</option>
     <option>UPE</option>
     <option>RW</option>
     <option>BH</option>
     </select></td></tr>
     
    <tr><td>Action</td><td>
     <select id="Action" name="Action">
     <option>Select an Action</option>
     <option>act_success</option>
     <option>dct_success</option>
     <option>act_fail</option>
     <option>dct_fail</option>
     </select></td></tr>
     
    <tr><td><br></td></tr>
     </table>
     
    <input type="submit" value="Submit" onclick="setSelectedValue('<%=PACK%>')">
     </form>
     <br>
     
    <%
     if(session.getAttribute("PACK")!=null&&session.get Attribute("CIR")!=null&&session.getAttribute("ACT" )!=null){
     String SMtxt=(String)request.getAttribute("SM");
     String ident=(String)request.getAttribute("IDE");
     
    %>
     <form action="CreateUpdate.jsp" method="post">
     Id:<input type="text" name="Identifier" value="<%=ident%>" maxlength="5" size="5" style="margin-left: 67px;">
     <br>
     SMS_TEXT:<input type="text" name="SMSTXT" value="<%=SMtxt%>" maxlength="50" size="50">
     <br>
     <input type="submit" value="update">
     </form>
     <%
     }
     else{out.println("Drop Down values are blanks");}
     if(request.getAttribute("Upd")!=null)
     {
     out.print("<font size='10' color='black' m>");
     //out.println("Data Updated");
     out.println("</font>");
     %>
     <script>
     alert("Data Updated");
     </script>
     <%
     }
     %>
     </body>
     </html>
    it is not working as expected i want to retain the value of drop down list which is not getting done properly using onclick event, selected value is getting reflected for a moment and then page go refresh...that is the problem...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: First JSP page

    What do you mean by "retain the value of a drop down list"?
    So, to take your code above, you have a screen with some drop downs (I'll only concentrate on the first form).
    How do you want it to function?

    Because at the moment you have a submit button that, onclick, sets a value on one of the drop downs, then submits the form.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    pawanjoshi is offline Member
    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Default Re: First JSP page

    Actually what i want to do here that whatever value i select on drop down list it is send to another page to do some calculation and after calculation, control goes to first page again and here the values selected by user on drop down list should be present as he selects at the time of input...as in given code the values got set when i click submit button but when control comes from second page to first page, drop down lists are loaded again and the values selected by user are gone...so i just want to know which event will be used to set the value when the control comes to first page so that drop down list values can be set at first page...

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: First JSP page

    So set the value selected in a drop down list when the page is loaded.
    Which is a Javascript problem...look up onLoad.

    Just declare some Javascript variables that contain the values you want to set.
    Java Code:
    <script>
    var packId = <%= session.getAttribute("PACK");%>;
    var circle = etc etc.
    </script>
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    pawanjoshi is offline Member
    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Default Re: First JSP page

    i tried am using onload with select and form tag but it doesn't work....

    Should i use it with some other tag in the given jsp page...

    With which tag it will work...

    pls suggest..

    Java Code:
    <select id="PackId" name="PackId" onload="setSelectedValue('<%=PACK%>','<%=CIR%>','<%=ACT%>');">
                        <option>Select a PackId</option>
                        <option>DEFAULT</option>
                        <option>EAUC</option>
                        <option>EAUCSONG0</option>
    </select></td></tr>

    And

    Java Code:
     <form action="process.jsp" method="post" style="margin-left: 540px;" onload="setSelectedValue('<%=PACK%>','<%=CIR%>','<%=ACT%>');">
                <table>
                    <tr><td style="color:navy;"><B></B></td></tr>
    		<tr><td><br></td></tr>
    		<tr><td>PackId</td><td>
                    <select id="PackId" name="PackId">
                        <option>Select a PackId</option>
                        <option>DEFAULT</option>
                        <option>EAUC</option>
                        <option>EAUCSONG0</option>
    		</select></td></tr>
                    
                    <tr><td>Circle</td><td>
                    <select id="Circle" name="Circle">
                        <option>Select a Circle</option>
                        <option>UPE</option>
                        <option>RW</option>
                        <option>BH</option>
    		</select></td></tr>
                    
                    <tr><td>Action</td><td>
                    <select id="Action" name="Action">
                        <option>Select an Action</option>
                        <option>act_success</option>
                        <option>dct_success</option>
                        <option>act_fail</option>
                        <option>dct_fail</option>
    		</select></td></tr>
                    
                    <tr><td><br></td></tr>
                </table>
             
                <input type="submit" value="Submit">
            </form>

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: First JSP page

    Either attach it to the <body> tag or window.onload = function etc etc.
    But this is now in the realms of Javascript, not Java.

    If it still doesn't work then you're going to need to debug it.
    First ensuring the correct values appear in the call to setSelectedValue, then checking that that function is actually being called.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    pawanjoshi is offline Member
    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Default Re: First JSP page

    if you don't mind please tell why it didn't work with select or form tag...

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default Re: First JSP page

    Because onload is not associated with those tags.
    Actually, it might be with <form>, but I can't guarantee that.
    If you need to know these things then I would suggest looking for Javascript forum.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 08-23-2011, 12:38 PM
  2. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 10:30 AM
  3. How to Export web page(jsp page) to excel using jsp or servlets or javascript
    By techsing14 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 05-25-2011, 11:08 AM
  4. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  5. warning that page has expired and i need to refresh the page again
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 07-15-2008, 01:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •