Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how do i use checkbox as an active/inactive button for a form?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i am trying to use a checkbox as a switch for a form . As in if i check the checkbox . i can edit in the form if i uncheck it , i cant edit it and cannot access it. Is there anyway to do it? i am new to this , so a detailed help will be appreciated . thank you.
And also i want help in this as well.. suppose this is how my jsp looks like..

[] name

myname [_____] add button view button


now if i press add .. i get an additional field to it . similar to the one above and it can iterate. Is it possible with struts ? or should i use javascript? if javascript then how do i add the tag content in the javascript function to make it work.

Sorry my code is a bit messed up. I am trying a lot to make it work


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="WEB-INF/tlds/struts-html" prefix="html"%>
<%@ taglib uri="WEB-INF/tlds/struts-logic" prefix="logic"%>
<%@ taglib uri="WEB-INF/tlds/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="javax.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="javax.naming.*"%>
<%@page import="javax.servlet.*"%>

<html>
<head>
<script type="text/javascript">



function addrow() {
var a = document.getElementById('myTable').insertRow(0);
var b = a.insertCell(0);
var c= a.insertCell(1);
var d= a.insertCell(2);
var e=a.insertCell(3);
b.innerHTML="My Name";
c.innerHTML="Text";
d.innerHTML="Add";
e.innerHTML="View Button";

}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Master Table</title>
</head>
<body>

<html:form action="/table" method="post" >
<table id="myTable" width="613" border="0" align="center" bgcolor="#CCCCCC">
<tr>
<th width="147" scope="col">

<div align="left">
<html:checkbox property="checked">SYSTEM
</html:checkbox>

</div>

</th>
<td width="218" scope="col"> </td>
<th width="234" scope="col"> </th>
</tr>
<tr>
<td> </td>
<c:set var="count" value="3"/>
<c:if test="${param.count>0}"><c:set var="count" value="${param.count}"/></c:if>
<c:forEach var="i" begin="1" end="${count}">
${i})
<td>My Name </td>
<td>
<html:text property="myName" />
<html:button property="add" value="Add" />
<html:button property="view" value="View" onclick="show_popup();" />
</td>
</c:forEach>
</tr>

</table>
</html:form>
</body>
</html>
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing that you are asking can be implemented by using javascript. Just give a unique ID to every text box and other input fields with a row number. Like if you have this structure

checkbox | name text box | age text box | button

And you have multiple rows with this type of arrangement, then you must have a naming convention for this. Like this must be the name for the fields in different rows

chk1 | name1 | age1 | button1
chk2 | name2 | age2 | button2

Now on the checking the check box, you can call a javascript function with a parameter like

<input type="checkbox" name="chk1" onclick="func(1)" />

now in the javascript you can have this type of code



I have not tried this code but it should work. Also for the other thing, I didn't understand the problem properly and neither am I a pro at struts. So I think you should ask it in the struts forum. I can give you a normal javascript solution if you want but you will have to provide some more details of the problem...
 
pratik mehta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks for the reply. it worked fine.. alright the second problem is that

i have a text field and an add button so everytime i click the add button i get a new text field.
how do i do that implementing javascript or struts?

how do i define the function for it?
 
Ankit Garg
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know about struts, but in javascript it is easy. The code that you have written looks good. What's the problem that you are facing??
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic