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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    automatically edit a table

    is there a way that i can put 5 text boxes on a page with a submit button and have it add the text to a form when i click the submit button? i searched google but i really didnt find anything. thanks
    Last edited by lithiumX; 01-18-2005 at 10:23 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Add the text to another form on the same page or on another page?

    Both are possible, but it depends on what you want to do.

    If it's on the same page you just have to get the data and change the value in the appropriate textfield. If you want it on another page, you'll have to pass the values as part of the URL and then use JS to get the variables from the URL and then change the appropriate textfields in the new form.
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, i meant to say table instead of form. i want to have a table with 5 columns and want to be able to add new rows with data in them by submitting the data using buttons. (so i wont have to write out the tags everytime i want to add data to the table) thanks again

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Or you wanting this is keep adding and saving the data? Cause if you are then it's not possible, as there's no way JS can store the data. The only thing it could do is during a session, display everything that is added, but as soon as the session is closed the data will be deleted.

    I'd use the pass the values to the same page. Get JS to grab the values and add them to an array in the head section of the page. Then where you want the table, have an loop that writes out a new line for the entries of the array.

    If this is what you want let me know and I'll put a script together for you. (or someone else may beat me to it )
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #5
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, if you could that would be great! thanks

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    WOW!! What a task and a half! lol

    I believe that the following page works pretty well, but the only concern i have is with the length of the url. The more times the submit button is pressed the longer the url gets. See if it's any use to you

    Code:
    <html>
    <head>
    <title>temporary file</title>
    
    <script>
    var sessionValues = new Array();
    
    var pairs=unescape(location.search.substring(1).replace(/\+/g," ")).split('&');
    for (var i=0;i<pairs.length;i++){
    	var pair = pairs[i].split('=');
    	this[pair[0]]=pair[1];
    }
    
    if (this['old1']){
    	for (j=1; this['old'+j]; j++){
    		sessionValues[sessionValues.length] = new Array(this['old'+(j)],this['old'+(j+1)],this['old'+(j+2)],this['old'+(j+3)],this['old'+(j+4)]);
    		j = j+4;
    	}
    }
    if (this['text1']){
    	sessionValues[sessionValues.length] = new Array(this['text1'],this['text2'],this['text3'],this['text4'],this['text5']);
    }
    </script>
    
    </head>
    <body>
    
    <form action="lithium.htm" method="GET">
    <script>
    text2write = "";
    k=1;
    for (i=0; i <sessionValues.length; i++){
    	for (j=0; j < sessionValues[sessionValues.length-1].length; j++){
    		text2write += "<input type=\"hidden\" name=\"old"+k+"\" value=\"";
    		text2write += sessionValues[i][j];
    		text2write += "\">";
    		k++;
    	}
    }
    
    document.write(text2write);
    </script>
    
    <input type="textbox" name="text1"><br>
    <input type="textbox" name="text2"><br>
    <input type="textbox" name="text3"><br>
    <input type="textbox" name="text4"><br>
    <input type="textbox" name="text5"><br>
    <input type="Submit" name="Submit" value="Submit">
    </form>
    
    <table>
    <script>
    text2write = "";
    for (i=0; i < sessionValues.length; i++){
    	text2write += "<tr>\n";
    	for (j=0; j < sessionValues[sessionValues.length-1].length; j++){
    		text2write += "<td>";
    		text2write += sessionValues[i][j];
    		text2write += "<//td>\n";
    	}
    	text2write += "</tr>\n";
    }
    
    document.write(text2write);
    </script>
    </table>
    </body>
    </html>
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #7
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes thats exactly what i needed. thanks very much!!


  •  

    Posting Permissions

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