By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

Concatenating dynamically created text box values

P: n/a
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>
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <25**************************@posting.google.com >,
we********@hotmail.com enlightened us with...
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[i]; //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
-------------------------------------------------
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.