Hi All,
Does anyone know how to validate a dynamically created table. I would like to know what is contained within the cells....
Humaira
| SitePoint Sponsor |

Hi All,
Does anyone know how to validate a dynamically created table. I would like to know what is contained within the cells....
Humaira

Hi humaira,
I normally write the table out in to a dynamically created window, then view the window's source.
Tristan

Hi
Cheers for the response!
Well to be honest I dont want the user to be seeing the table twice correct me if i am wrong by creating a dynamic window means that the table would be output to a new window which the user would be able to view...

I'm a little confused, I understood that you wanted to see and validate the X/HTML markup generated by your script? Writing the contents in to a new window and viewing the windows source is just a handy way of checking/validating your scripts output.
I only do this in development, while I'm testing a client-side script. Have I misunderstood?
Tristan





u cant view a dinamicaly created table source....
u can just add a function to your create table button to insert this html code into some textarea with innerHTML...
cheers![]()

hey thanks for the response is it possible for you to give me an example cuz I am not really understanding this lol
well the table itself is created within HTML but the rows for the table are appended dynamically
here is the code:
function appendRow( tableID ) {
var table = document.getElementById( tableID );
if( table && table.insertRow ) {
var row = table.insertRow( -1 ), cells = [];
if(row) {
for( var i = 0; i < 4; ++i ) {
cells[ i ] = row.insertCell( -1 );
}
if( cells[ 0 ] && cells[ 0 ].appendChild && document.createElement ) {
var button = document.createElement('button');
if( button ) {
appendText( button, 'Delete' );
addListener( button, 'click', deleteRow );
cells[ 0 ].appendChild( button );
}
}
if(cells[1]&&cells[1].appendChild && document.createElement)
{
var e1= document.createElement('input');
e1.setAttribute('type','text');
e1.setAttribute('name','field'+count);
e1.setAttribute('id','fieldo');
e1.setAttribute('value','field'+count);
cells[1].appendChild(e1);
}
if(cells[2]&&cells[2].appendChild && document.createElement)
{
var e1= document.createElement('input');
e1.setAttribute('type','text');
e1.setAttribute('size',4);
e1.setAttribute('name','type'+count);
cells[2].appendChild(e1);
}
if(cells[3]&&cells[3].appendChild && document.createElement)
{
var e1= document.createElement('input');
e1.setAttribute('type','text');
e1.setAttribute('size',35);
e1.setAttribute('name','desc'+count);
count++;
cells[3].appendChild(e1);
}
}
}
Cheers for your help....

Originally Posted by tristanm
See I think there has been a little misunderstanding I have created the rows dynamically within javascript the rows created contains text fields for user input. Upon submission I want to validate the contents of the text fields....

ok, I think I understand now. This is the first time you've mentioned anything about a form!Originally Posted by humaira
![]()
So, basically you want to validate form input for a form that is dynamically generated. To be honest, I've never had to do anything like this, so off hand I can't offer you any advice. Is it not possible to validate the dynamically generated form like you would any other? What have you tried thus far?

Ooops guess I never mentioned that anyway I have tried the following I have tried to serach on the net but I have had no luck so far
var table = document.getElementById("testTable"),cells = [];
var rows=[];
var table_size = table.rows.length;
alert(getCellValue(table.rows[2].cells[1]));
well tried that because I thought I would be referencing the individual cells within the table. Also I dont know whether getAttribute would be of any help to this problem since I know setAttribute can be used to set the value of a text field I thought by using getAttribute it would give the value but no luck with that too...
Also when I created the text fields I have given them unique identifiers so that I can access them through php well I tried accessing them textfields using their names but because as they are created dynamically there is no reference to them in php....

Originally Posted by humaira
Thats what i meant to say and not php

I'm confused again! At what point are you trying to validate the form entries, and are you attempting to do it in client side Javascript, or PHP? If you're doing it via PHP, surely you retrieve the form fields from the $_POST collection when the form is submitted?
I think it might be beneficial if you could explain briefly what it is you're actually trying to do. I should warn you though, its starting to sound like the heart of your problem revolves around the DOM and PHP, neither of which are my strong points. I'd like to know what you're attempting to do though all the same, just for my own sanity![]()

lol Well what I am trying to do is to validate the dynamic text fields that were created using Javascript before the form containing the dynamic table is posted to a php page....

Right, I understand. Well, if you can't access the dynamically generated fields via the DOM, then I'm equally stumped. I've never written any client side script that generates elements, but I had always assumed that once they had been created, they were accessible via the DOM just like any normal static elements?
After all that I can't offer any help![]()
Sorry.

Hey no probs well if you do find out within the near future let me know but I have tried to search on net too havent had much luck but anyway if I do get a solution I will definately post it up because its been a tough problem!
cheers for your input...
Humaira

ok well i think i have sought a solution for the problem jus sorting it out now butlooks promising that is when u actually create the fields associate ids with them and therefor you are able to traverse through the fields....
Bookmarks