Solved

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

Posted on 2006-11-13
8
237 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
getting Http 404 error in jsp forms 8 79
getting param value 7 53
maven project jars 7 53
Suggestion on WebSite Template Sites 6 101
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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