Solved

JSP - where the radio button is clicked, it brings a record info to the next page???????

Posted on 2006-11-13
8
233 Views
Last Modified: 2010-04-01
I have a jsp page which lists of the records along with the radio button. Where the radio button is clicked, it needs to bring the record info to the next page. The problem is i dont know how to do it.

I think this is very common, but i have no idea how to do it.

Below is a part of my codes

      <table border="1" cellspacing="1" cellpadding="1">
       <sql:query var="qrySRtype" >
               SELECT sr_type_code, sr_type_descr FROM tmp_sr_type
      </sql:query>

        <tr>
         <th width="20%">Code</th>
         <th width="50%">Description</th>
         <th width="10%">Select</th>
       </tr>  

       <%-- Get the value of each column while iterating over rows --%>
       <c:forEach var="row" items="${qrySRtype.rowsByIndex}">
         <tr>
           <c:forEach var="column" items="${row}">
             <td><c:out value="${column}"/></td>
           </c:forEach>
           <th><input type="radio" name="SelectSRtype" value="Y"/></th>
         </tr>
       </c:forEach>
    </table>

===================================================================
Where the radio button, SelectSRType is clicked, i need to pass the code and description to the next page
0
Comment
Question by:LeanMoreTryMore
  • 4
  • 2
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
boonleng earned 300 total points
ID: 17935161
You can pass the code to the next page by submititng the form when user click on the radio.
Example:
       <c:forEach var="row" items="${qrySRtype.rows}">
         <tr>
           <th><c:out value="${row.sr_type_code}"/></th>
           <th><c:out value="${row.sr_type_descr}"/></th>
           <th><input type="radio" name="SelectSRtype"
                             value="<c:out value="${row.sr_type_code}"/>"
                              onclick="this.form.submit()"/></th>
         </tr>
       </c:forEach>

Or passing the info by url parameter.
Example:
<input type="radio" name="SelectSRtype" value="Y"
          onclick=" window.location.href='nexpage.jsp?code=<c:out value="${row.sr_type_code}"/>' "/>
0
 

Author Comment

by:LeanMoreTryMore
ID: 17935259
But the submit button is not next to the radio button.

See below code

      <table border="1" cellspacing="1" cellpadding="1">
       <sql:query var="qrySRtype" >
               SELECT sr_type_code, sr_type_descr FROM tmp_sr_type
      </sql:query>

        <tr>
         <th width="20%">Code</th>
         <th width="50%">Description</th>
         <th width="10%">Select</th>
       </tr>  

       <%-- Get the value of each column while iterating over rows --%>
       <c:forEach var="row" items="${qrySRtype.rowsByIndex}">
         <tr>
           <c:forEach var="column" items="${row}">
             <td><c:out value="${column}"/></td>
           </c:forEach>
           <th><input type="radio" name="SelectSRtype" value="Y"/></th>
         </tr>
       </c:forEach>
    </table>
    <table cellspacing="0" cellpadding="2" border="0" width="100%">
        <tr>
          <th width="12%" align="right">
            <font color="#ff0000">
              *
            </font>
             Name
          </th>
          <td width="76%">
              <h:inputText binding="#{backing_CreateSR.inputText1}"
                           id="inputText1" required="true" size="55"/>
              <h:message for="inputText1" binding="#{backing_CreateSR.message1}"
                         id="message1"/>
            </td>
        </tr>
        <tr>
          <th width="12%" align="right">
            <font color="#ff0000">
              *
            </font>
             Address Line1
          </th>
          <td width="76%">
              <h:inputText binding="#{backing_CreateSR.inputText2}"
                           id="inputText2" size="55" required="true"/>
              <h:message for="inputText2" binding="#{backing_CreateSR.message2}"
                         id="message2"/>
            </td>
        </tr>
      </table>
      <table width="100%">
        <tr></tr>
        <tr>
          <th align="right" width="12%"><input type="reset" value="Reset" align="middle"/></th>
          <th align="left" width="75%">
              <h:commandButton value="submit"
                               binding="#{backing_CreateSR.commandButton1}"
                               id="commandButton1"
                               action="success"/>
            </th>
        </tr>
      </table>

===========================================
0
 
LVL 14

Expert Comment

by:boonleng
ID: 17936045
User javascript to submit the form when user click on radio button.
Example:
<input type="radio" name="SelectSRtype" value="<c:out value="${row.sr_type_code}"/>"
                              onclick="this.form.submit()"/>
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 200 total points
ID: 17939153
you will need a little java script to take the values from the row and submit it to a page..

<input type="radio" name="SelectSRtype" value="<c:out value="${row.sr_type_code}"/>"
                              onclick="getRow(this)"/>

function getRow ( row)
{
var mycells = row.parent.cells;
code=mycells[1].innerText;
Desc=mycells[2].innerText;
//do whatever you want to do with these values, move it to hidden fields or append to the url.
document.forms[0].submit();
}

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:LeanMoreTryMore
ID: 17950754
sorry i haven't responded your answer.
I was sick yesterday. now i'm back working this one again

NOTES. only the SUBMIT botton is clicked, it then goes to the next pages.

How do i invoke a java script when the submit button is click.

<h:form binding="#{backing_CreateSR.form1}" id="form1">

Let's say i use Kuldeepchaturvedi's java script, please advise how to pass code and descr to the next page

The following is faces-config.xml -- Notes i also use JSF for page navigation

<faces-config xmlns="http://java.sun.com/JSF/Configuration">
  <navigation-rule>
    <from-view-id>/CreateSR.jsp</from-view-id>
    <navigation-case>
      <from-outcome>success</from-outcome>
      <to-view-id>/CreateSR_Action.jsp</to-view-id>
    </navigation-case>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 17951291
create two hidden fields and move the values to these fields..
dont invoke any javascript at submit.. ( the values are getting moved when user clicked on the radio button..)

var mycells = row.parent.cells;
code=mycells[1].innerText;
Desc=mycells[2].innerText;
yourhiddenfield.value=code;
yourhiddnefielddesc.value=desc;
}

now when you submit.. these hidden fields will carry the values from the table..
0
 

Author Comment

by:LeanMoreTryMore
ID: 17960120
I failed to call the java script in which i add the debug message..WHY...

Java script

<script type="text/javascript">
function getRow ( row) {
  var mycells = row.parent.cells;
  code=mycells[1].innerText;
  Desc=mycells[2].innerText;
  //do whatever you want to do with these values, move it to hidden fields or append to the url.
  alert("code:" + code + " | Desc:" + Desc);
}
</script>


I have created 2 hidden fields where the radio button is clicked, it supposes to call the getRow function, but it is not, it doesn't show the debug message

**** onclick="getRow(row) <=== is it the way how to pass the row

           <th><input type="radio" name="SelectSRtype" value="Y" onclick="getRow(row)"/>
                <input type="hidden" name="hSrTypeDesc"/>
                <input type="hidden" name="hSrTypeCode"/>
           </th>
0
 

Author Comment

by:LeanMoreTryMore
ID: 17960614
I work it out how to do it.

Thanks all
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Spring Tuorial 1 107
Run jasper report from servlet 1 206
doubleChar java challenge 7 97
withoutString  challenge 40 149
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now