Concatenating dynamically created text box values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chi

    Concatenating dynamically created text box values

    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="javas cript">
    function AddURL()
    {
    var theTable = document.getEle mentById('tblUR L');
    var URL = document.getEle mentById('URL') .value;

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

    // create new cell objects
    var urlTextCell = document.create Element("td");
    var urlEditCell = document.create Element("td");
    var previewButtonCe ll = document.create Element("td");
    var deleteButtonCel l = document.create Element("td");

    // create text field for urlEditCell
    var newInput = document.create Element("INPUT" );
    newInput.type= "text";
    newInput.value = URL;
    urlEditCell.app endChild(newInp ut);

    // create a preview/test button and add to the previewButtonCe ll
    var newInput = document.create Element("INPUT" );
    newInput.type= "button";
    newInput.value = "Test";
    newInput.onclic k = new Function("previ ewURL('"+ URL + "')");
    previewButtonCe ll.appendChild( newInput);

    // create delete button and add to the deleteButtonCel l
    var newInput = document.create Element("INPUT" );
    newInput.type= "button";
    newInput.value = "Delete";
    newInput.onclic k = DeleteURL;
    deleteButtonCel l.appendChild(n ewInput);

    // set the text and buttons of each cell
    newRow.appendCh ild(urlTextCell );
    newRow.appendCh ild(urlEditCell );
    newRow.appendCh ild(previewButt onCell);
    newRow.appendCh ild(deleteButto nCell);

    // create a new row and replace it with your created row
    var tempRow = theTable.insert Row();
    tempRow.replace Node(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.srcElemen t.parentElement .parentElement;
    theRow.removeNo de(true);
    }

    function previewURL(theU RL)
    {
    window.showModa lDialog(theURL, "","dialogHeigh t: 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.s ubmit();
    }
    return true;
    }
    </script>
    </head>
    <body onLoad="documen t.frmURL.reset( );"></body>
    <form action="" name="frmURL" onSubmit="retur n myValidate(fals e)">
    <fieldset style="padding: 5px; margin-bottom:3px;">
    <legend>Alterna te Content URL(s)</legend>
    <br>
    <input id="URL" type="text" size="35"
    value="http://www.cnn.com"><i nput 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>
  • kaeli

    #2
    Re: Concatenating dynamically created text box values

    In article <25d4a987.03101 61218.42aa98fb@ posting.google. com>,
    webjunk4me@hotm ail.com enlightened us with...[color=blue]
    > 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!
    >[/color]

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

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

    -------------------------------------------------
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu
    thinks you'd make a nice sandwich.


    -------------------------------------------------

    Comment

    Working...