Solved

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

Posted on 2006-11-13
8
234 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
handling Struts tag, JSTL tag and scriptlet in Ajax. 7 171
change size of out.write buffer 1 87
TreeSet comparator example 7 90
spring example errors 33 259
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

11 Experts available now in Live!

Get 1:1 Help Now