Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-13
8
Medium Priority
?
242 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 1200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 800 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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your business may be under attack from a silent enemy that is hard to detect. It works stealthily in the shadows to access and exploit your critical business information, sensitive confidential data and intellectual property, for commercial gain. T…
In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

877 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