[Javascript] Re:posting arrays

Esther_Strom at hmco.com Esther_Strom at hmco.com
Tue Oct 9 08:14:33 CDT 2001


Don't know if this will work in actuality, but theoretically (ah, how often
we hear that!)...

Why not create a semicolon (or tilde, or some other uncommon character) -
delimited text string (link1~link2~link3). Set that as a hidden input and
post to the next page. Then have a function on the next page split out the
elements using split().


var my_links = "link1~link2~link3~link4"; //pass this as a hidden element

var link_array = my_links.split("~");

for (loop=0; loop < link_array.length;
loop++)

{

   document.writeln(link_array[loop] + " is a link to delete.<br>");

}

"This breaks the string my_links into an array of five elements. (Happily,
JavaScript creates the array for you automatically, so you don't have to
use new Array() to create it yourself). "

(Above courtesy of Webmonkey...)



                                                                                                                           
                    "Bill Marriott"                                                                                        
                    <bill.marriott at optusn        To:     <javascript at LaTech.edu>                                           
                    et.com.au>                   cc:                                                                       
                    Sent by:                     Subject:     [Javascript] Re:posting arrays                               
                    javascript-admin at LaTe                                                                                  
                    ch.edu                                                                                                 
                                                                                                                           
                                                                                                                           
                    10/04/01 10:27 PM                                                                                      
                    Please respond to                                                                                      
                    javascript                                                                                             
                                                                                                                           
                                                                                                                           




Hi Everyone,

Thanks for your help in the past.

I have a new problem with posting arrays.

I want to use an array

var linksToDelete = new Array();

to store the ID's of records to delete from the database.

I have got the javascript (see below) to add the elements to the array as
the user deletes a record from the page.

How can I post the array(with all the elements) to the next page in order
to do the processing for the deletes. The <input hidden tag> dosen't want
to post the array!



<SCRIPT LANGUAGE=Javascript>
var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);

var linkCount = <?MIVAR>$LINKCOUNT<?/MIVAR>;
var linksToDelete = new Array();
var deleteCount = 0;

function removeRow(e)
{
if (confirm("Do you want to delete this row?"))
   {
 if (ns)
 {
  var srcElement = e.target;
 }
 else
 {
  var srcElement = event.srcElement;
 }
 if (srcElement.nodeType == 3)
 {
  srcElement = srcElement.parentNode;
 }
 var delRow = srcElement.parentNode.parentNode;
 var tBodyObj = document.getElementById("linkTBody");
        linksToDelete[deleteCount] = delRow.id;
        alert(linksToDelete[deleteCount]);  ////this works here
        document.editTable.LINKSTODELETE[deleteCount].value=delRow.id; ////
THIS LINE IS NOT WORKING
        deleteCount++;
        tBodyObj.removeChild(delRow);
        linkCount--;
        document.editTable.LINKCOUNT.value=linkCount; ////single input
hidden tag in the form
        document.editTable.DELETELINKCOUNT.value=deleteCount; //// single
input hidden tag in the form
   }
else
   {
    ////cancel;
   }
}
</SCRIPT>

<INPUT TYPE="hidden" name="LINKCOUNT" Value="<?MIVAR>$LINKCOUNT<?/MIVAR>">
<INPUT TYPE="hidden" name="LINKSTODELETE[]" >
<INPUT TYPE="hidden" name="DELETELINKCOUNT" Value="0">







More information about the Javascript mailing list