Concatenating dynamically created text box values

C

Chi

Hi There,

The following is a popup form that works exactly as I want but I now
need to get the values of each text box added when a user clicks the
'Add' button and pass the values back the opener form into a textarea.

Thanks in advance!

================================
CODE BELOW
================================

<html>
<head>
<script language="javascript">
function AddURL()
{
var theTable = document.getElementById('tblURL');
var URL = document.getElementById('URL').value;

// create a new row object
var newRow = document.createElement("tr");

// create new cell objects
var urlTextCell = document.createElement("td");
var urlEditCell = document.createElement("td");
var previewButtonCell = document.createElement("td");
var deleteButtonCell = document.createElement("td");

// create text field for urlEditCell
var newInput = document.createElement("INPUT");
newInput.type= "text";
newInput.value = URL;
urlEditCell.appendChild(newInput);

// create a preview/test button and add to the previewButtonCell
var newInput = document.createElement("INPUT");
newInput.type= "button";
newInput.value = "Test";
newInput.onclick = new Function("previewURL('"+ URL + "')");
previewButtonCell.appendChild(newInput);

// create delete button and add to the deleteButtonCell
var newInput = document.createElement("INPUT");
newInput.type= "button";
newInput.value = "Delete";
newInput.onclick = DeleteURL;
deleteButtonCell.appendChild(newInput);

// set the text and buttons of each cell
newRow.appendChild(urlTextCell);
newRow.appendChild(urlEditCell);
newRow.appendChild(previewButtonCell);
newRow.appendChild(deleteButtonCell);

// create a new row and replace it with your created row
var tempRow = theTable.insertRow();
tempRow.replaceNode(newRow);

// reset cell and set focus for next entry
document.frmURL.URL.focus();
document.frmURL.URL.value = '';
}

function DeleteURL()
{
// grab the containing row
var theRow = event.srcElement.parentElement.parentElement;
theRow.removeNode(true);
}

function previewURL(theURL)
{
window.showModalDialog(theURL,"","dialogHeight: 500px; dialogWidth:
500px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help:
No; resizable: Yes; status: No;");
}

var validated = false;

function myValidate(mode)
{
if (!mode && !validated) return false;
if (mode)
{
validated=true; formReference.submit();
}
return true;
}
</script>
</head>
<body onLoad="document.frmURL.reset();"></body>
<form action="" name="frmURL" onSubmit="return myValidate(false)">
<fieldset style="padding: 5px; margin-bottom:3px;">
<legend>Alternate Content URL(s)</legend>
<br>
<input id="URL" type="text" size="35"
value="http://www.cnn.com"><input type="button" value="Add"
onclick="AddURL()"/>
<br>
<br>
<table border="0" cellspacing='3' id ="tblURL"></table>
</fieldset>
<div align="right">
<input type="button" value="Save" onClick="">
<input type="button" value="Cancel" onClick="">
</div>
</form>
</body>
</html>
 
K

kaeli

Hi There,

The following is a popup form that works exactly as I want but I now
need to get the values of each text box added when a user clicks the
'Add' button and pass the values back the opener form into a textarea.

Thanks in advance!

Substitute your form names in the code. Assumes you want the values of
ALL text elements in the form.

var s="";
var l = document.formName.elements.length; //popup form name here
for (var i=0; i<l; i++)
{
e = document.formName.elements; //popup form name here
if (e.type=="text") s+= e.value+" "; // space between values so
one can read them
}
opener.document.formName.elementName.value = s; //opener form name and
the textarea name here

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top