Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inserting the value of a text box that's inside a table into an array?

    hi there,

    i Need a bit of a hand with "inserting the value of a text box that's inside a table into an array" so what I'm looking for is some code that will take whats in the text box then make a place in the array and store it there. the array must have no set size. wondering is it something to do with push or pop?

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    Quote Originally Posted by monkeycoder View Post
    hi there,

    i Need a bit of a hand with "inserting the value of a text box that's inside a table into an array" so what I'm looking for is some code that will take whats in the text box then make a place in the array and store it there. the array must have no set size. wondering is it something to do with push or pop?


    this should do.
    the array will be set by the table.
    you might have to steer the code a bit for your project, but this should get you started...

    Code:
    <table>
    <tr>  <td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    </tr><tr>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    </tr><tr>	
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    	<td><input type='text'  /></td>
    </tr></table>
    
    <br />
    
    <textarea id="ta1" rows="15"  cols="60" ></textarea>
    
    <script>
    
    var ray=[[]];  //the array to store table changes
    
    // some support code
    function el(tid) {    return document.getElementById(tid);}
    function tags(elm){ var o=[], i=0,  r=document.getElementsByTagName(elm), mx=r.length; for(var z=0;z<mx ;z++)   {o[z]=r[z]} ; return o;   }
    function getParent(elm, tagname) { tops:for (var z = 0; z < 99; z++) {var t = elm.parentNode ? elm.parentNode : elm.parentElement ? elm.parentElement : elm;if (!t.tagName) {return elm;}if (!tagname) {return t;}if (tagname==(tagname * -1 )) {if (z == tagname) {return t;}elm = t;continue tops;}if (t.tagName.toLowerCase().match(tagname.toLowerCase())) {return t;}elm = t;}}
    
    
    
    //custom code below 
    for(var z=0, mx=tags("tr").length; z<mx;z++){ ray[z]=[];    } //init array by length of table row (writing a col to an undefined row cause error!)
    
    for(var z=0,tg=tags("input"), mx=tg.length; z<mx;z++){  //updrage all the text inputs to modify the array
    var t=tg[z];
    	t.value=0;    
    	t.size=4;
    	t.setAttribute("onchange","doRay(this)");
    }//next text input
    
    function doRay(t){ //modify the array with the value of the cell
    	var col=getParent(t, "td").cellIndex ||0;
    	var row=getParent(t, "tr" ).rowIndex || 0;
    	ray[row][col]=t.value;
    	el("ta1").value=ray.join("\n");
    }//end function doRay update
    
    </script>
    Last edited by rnd me; 12-13-2007 at 09:18 AM. Reason: clarity
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •