I have a .jsp page where I have 3 struts tags (1 checkbox, 1 select tag, 1 textfield) and below these I have anchor tag to add more fields. So, when you click the anchor tag the javascript will add the 3 struts field below the one existing (something like attach file function in gmail). I am allowing maximum five field additions. However I have questions that when the user fills all these fields and clicks submit how can I collect all the data as the name attribute for all the 3 struts fields are only declared once and rest is dynamic addition using javascript. please help...........
sample code------below - <s:checkbox name="chec" id="chec"></checkbox>
-
<s:select name="file" id="file" value="email; TXT; voicemai></select>
-
<s:textfield name="text" id="text"></textfield><br>
-
<a href="javascript:adduploat(4,'chec', 'file', 'text')">add more fields</a>
---
and then you get dynamically same fields below this...so how should I collect all the data and display them in another .jsp page..
3 8972
you are aware that the shown code is not even well-formed?
Also could we see your adduploat function please?
This page has the addupload function. So, the question is clear to you guys that I am adding the struts tags repeatedly using javascript and I want to collect all the information from the form. So, basically they share same 'name' attribute.
I am also attaching a screen shot for your reference of what actually the form looks like.
here is the code - <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
-
pageEncoding="ISO-8859-1"%>
-
<%@ taglib prefix="s" uri="/struts-tags" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-
<title>Notification Services</title>
-
<SCRIPT type="text/javascript">
-
function toggleDisplay(attachments){
-
element = document.getElementById('attachments').style;
-
if (element.display=='none') {element.display='block';}
-
else {element.display='none';}
-
}
-
-
var max = 0; // maximum # of attachments allowed
-
var currentUploads = 0; // current # of attachment sections on the web page
-
var nameDesc = ''; // Name property for the Description Input field
-
var nameFile = ''; //Name property for the File Input field
-
var nameChec = ''; // Checkbox property for the File Input field
-
var scrollPosVert = 0; // stores the current scroll position on the form
-
// for some reason when a div is taken out, the form
-
// will scroll to the top on both Firefox and IE
-
-
// SCROLL FUNCTIONS
-
function saveScrollPos(offset)
-
{
-
scrollPosVert=(document.all)?document.body.scrollTop:window.pageYOffset-offset;
-
}
-
-
function setScrollPos()
-
{
-
window.scrollTo(0, scrollPosVert);
-
setTimeout('window.scrollTo(0, scrollPosVert)',1);
-
}
-
-
-
-
-
// This function adds a new attachment section to the form
-
// It is called when the user clicks the "Add contact" button...
-
// It takes three arguments:
-
// maxUploads - the maximum number of attachments allowed
-
//checFieldName - the name for checkbox type
-
// descFieldName - the field name for the Description Input field
-
// fileFieldName - the field name for the File Input field
-
function addUpload(maxUploads, checFieldName, descFieldName, fileFieldName)
-
{
-
nameDesc=descFieldName;
-
nameFile=fileFieldName;
-
nameChec=checFieldName
-
max = Number(maxUploads);
-
-
currentUploads++;
-
if (currentUploads>max) return;
-
-
if (currentUploads>0)
-
document.getElementById('addupload').childNodes[0].data='Add more contacts';
-
-
if (currentUploads==max) document.getElementById('addupload').childNodes[0].data='Max level reached';
-
-
-
// First, clone the hidden attachment section
-
var newFields = document.getElementById('attachment').cloneNode(true);
-
newFields.id = '';
-
-
-
// Make the new attachments section visible
-
newFields.style.display = 'block';
-
-
-
-
// loop through tags in the new Attachment section
-
// and set ID and NAME properties
-
-
-
var newField = newFields.childNodes;
-
for (var i=0;i<newField.length;i++)
-
{
-
-
if (newField[i].name==nameChec)
-
{
-
newField[i].id=nameChec+currentUploads;
-
newField[i].name=nameChec+currentUploads;
-
}
-
-
if (newField[i].name==nameFile)
-
{
-
newField[i].id=nameFile+currentUploads;
-
newField[i].name=nameFile+currentUploads;
-
}
-
-
if (newField[i].name==nameDesc)
-
{
-
newField[i].id=nameDesc+currentUploads;
-
newField[i].name=nameDesc+currentUploads;
-
}
-
}
-
-
-
// Insert our new Attachment section into the Attachments Div
-
// on the form...
-
var insertHere = document.getElementById('attachmentmarker');
-
insertHere.parentNode.insertBefore(newFields,insertHere);
-
}
-
-
-
-
-
-
// This function removes an attachment from the form
-
// and updates the ID and Name properties of all other
-
// Attachment sections
-
function removeFile(container, item)
-
{
-
// get the ID number of the upload section to remove
-
var tmp = item.getElementsByTagName('input')[0];
-
var basefieldname = '';
-
if (tmp.type=='text') basefieldname = nameDesc; else basefieldname = nameFile;
-
-
-
var iRemove=Number(tmp.id.substring(basefieldname.length, tmp.id.length));
-
-
// Shift all INPUT field IDs and NAMEs down by one (for fields with a
-
// higher ID than the one being removed)
-
var x = document.getElementById('attachments').getElementsByTagName('input');
-
for (i=0;i<x.length;i++)
-
{
-
if (x[i].type=='text') basefieldname=nameDesc; else basefieldname=nameFile;
-
-
var iEdit = Number(x[i].id.substring(basefieldname.length, x[i].id.length));
-
if (iEdit>iRemove)
-
{
-
x[i].id=basefieldname+(iEdit-1);
-
x[i].name=basefieldname+(iEdit-1);
-
}
-
}
-
currentUploads--;
-
saveScrollPos(0);
-
container.removeChild(item);
-
setScrollPos();
-
document.getElementById('addupload').style.visibility='visible';
-
if (currentUploads==0)
-
document.getElementById('addupload').childNodes[0].data='Attach a file';
-
}
-
-
//remove the last add contact info elments from the span
-
function removeFilelast(container, item)
-
{
-
// get the ID number of the upload section to remove
-
var tmp = item.getElementsByTagName('input')[0];
-
var basefieldname = '';
-
if (tmp.type=='text') basefieldname = nameDesc; else basefieldname = nameFile;
-
-
-
var iRemove=Number(tmp.id.substring(basefieldname.length, tmp.id.length));
-
-
// Shift all INPUT field IDs and NAMEs down by one (for fields with a
-
// higher ID than the one being removed)
-
var x = document.getElementById('attachments').getElementsByTagName('input');
-
for (i=0;i<x.length;i++)
-
{
-
if (x[i].type=='text') basefieldname=nameDesc; else basefieldname=nameFile;
-
-
var iEdit = Number(x[i].id.substring(basefieldname.length, x[i].id.length));
-
if (iEdit>iRemove)
-
{
-
x[i].id=basefieldname+(iEdit-1);
-
x[i].name=basefieldname+(iEdit-1);
-
}
-
}
-
currentUploads--;
-
saveScrollPos(0);
-
container.removeChild(item);
-
setScrollPos();
-
document.getElementById('addupload').style.visibility='visible';
-
if (currentUploads==0)
-
document.getElementById('addupload').childNodes[0].data='Attach a file';
-
}
-
-
-
-
-
-
</SCRIPT>
-
<link href="<s:url value="/CSS/style.css"/>" rel="stylesheet" type="text/css"/>
-
</head>
-
-
<body>
-
<div id="welcome"><h4 align="center">Hello, please add our notification services to
-
your VIN# <s:property value="message"/></h4></div>
-
-
<div id="container">
-
<div id="padding_container">
-
<div id="header">
-
<div id="header1"><h3>NOTIFICATIONS</h3></div>
-
<P align="left"><font face="Times New Roman, Times, serif">Find out immediately if there is an issue with your vehicle,
-
such as an attempted break-in or a red alert in your OnStar Vehicle
-
Diagnostics report. Simply enroll in our notifiaction services and we'll let you know right away via your preferred You can edit your preferences and contacts at any time after enrolling.
-
</font></P>
-
</div>
-
<div id="wrapper">
-
<div id="navigation" align="center" >Theft Notifications<br>
-
<a href="javascript:toggleDisplay('attachments')">Enroll Now</a>
-
</div>
-
-
<div id="content">
-
<p align="left"><strong>Opt In Theft Notifications</strong><br>
-
Some text to simplifySome text to simplifySome text to simplifySome text to simplifySome text to simplify
-
Some text to simplifySome text to simplifySome text to simplify<br>
-
<a href="#">Read Sample Email</a>, <a href="#">Read SAmple TEXT/SMS</a>, <a href="#">Hear Sample Voicemail</a></p>
-
</div>
-
</div>
-
-
<div id="attachment" class="attachment" style="display:none">
-
<s:checkbox id="chec" name="chec" name='OnOff' value=''/>
-
<s:select
-
name="file"
-
id='file'
-
headerKey="1"
-
headerValue="-- Please Select --"
-
list="#{'01':'Email','02':'SMS/TXT','03':'Voicemail'}"
-
/>
-
<s:textfield id="desc" name="desc" maxlength="55" size="55"/>
-
-
-
<a href="#" onclick="javascript:removeFile(this.parentNode.parentNode,this.parentNode);">Delete</a>
-
-
-
</div>
-
-
<div id="attachments" class="container" style="display:none">
-
<table><tr><td width="15%"><strong>On/Off</strong></td>
-
<td width="25%"><strong>Contact</strong></td>
-
<td width="35%%"><strong>Information</strong></td>
-
</tr></table>
-
<div id="attachmentssub" >
-
<s:checkbox id="chec" name="chec" name='OnOff' value=''/>
-
<s:select
-
name="file"
-
id='file'
-
headerKey="1"
-
headerValue="-- Please Select --"
-
list="#{'01':'Email','02':'SMS/TXT','03':'Voicemail'}"/>
-
<s:textfield id="desc" name="desc" maxlength="55" size="55"/>
-
<a href="#" onclick="javascript:removeFilelast(this.parentNode.parentNode,this.parentNode);">Delete</a></div><br>
-
<span id="attachmentmarker"></span>
-
<a id="addupload" style="floar:left;" href="javascript:addUpload(4, 'chec', 'desc', 'file')">Add Contact Information</a>
-
<s:submit action="SaveButton" cssStyle="float:right;" value="save"></s:submit><button type="button2" style="float:right;">Cancel</button><!-- <button type="button1" style="float:right;">Save</button> -->
-
-
</div>
-
-
<div id="wrapper1">
-
<div id="OVD" align="center" >OVD Notifications<br>
-
<a href="#">Enroll Now</a></div>
-
-
<div id="OVD_content">
-
<h2>Content</h2>
-
<p>Some sample content, add your own here</p>
-
</div>
-
</div></div>
-
</div>
-
</body>
-
</html>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Glen |
last post by:
I have a list of beans that I retrieved from a database. These beans
are all of the same class. Now I want to display these beans in a
struts form so that the user can modify the data in the...
|
by: Alex M |
last post by:
I'm trying to use the jakarta struts client side javascript validators
and the validators are working, but they are not showing the popup
messages. I have the message keys defined in the...
|
by: nc |
last post by:
My iterator can find my collection when my Action class calls my jsp
directly, however when my Action class calls an html file that is set
up with IFrames (one of which is loading that same jsp), I...
|
by: sancha |
last post by:
Hi,
i am in a bit of a delima here.
I need to submit an action through javascript
so i used
document.forms.action='/search.do?&submitaction=Add Minus'
document.forms.submit();
since i am...
|
by: =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= |
last post by:
Hello,
I've been trying to figure something out for the past few days and I
can't seem to pinpoint what I'm doing wrong.
I've been trying to call javascript from inside a <logic:equal>, but...
|
by: nithiya sri |
last post by:
i am new to struts.I try running struts application in Eclipse with the tomcat plug in ..
it shows the following error:;
please help me in this...
SEVERE: Error loading WebappClassLoader
...
|
by: eunever32 |
last post by:
Hi
I have a struts (1.1) form
<html:form
<html:text
<html:text ...
|
by: nghivo |
last post by:
I have a Struts application developed following the MVC method (forms, actions, beans, etc)..
I have a JSP page with 2 buttons A and B. When B is clicked, a Struts action will be executed.
But...
|
by: shrik |
last post by:
hi everybody.
I have following problem.
There are two pages. index.jsp and main.jsp in my application
Index.jsp contains logging interface in .
It submits password and userid to loginform bean.
...
|
by: ajos |
last post by:
hi frnds,
the situation is im developing a web application in struts--
my specifications-eclipse3.2.2,struts1.1,tomcat5.5.23 mysql5.0 db.
the scenario-i have a jsp page which adds the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |