Solved

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

Posted on 2006-11-13
8
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 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
 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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