Hi All, I am in the process of putting together a weg page. Altough all the information defined in my function appears (in table) under the table it says undefined??? just under the table caption Please see code below, any ideas on how to get rid of this error? Any ideas???? document.write(test()); function test() { document.write('<center><table width="50%" border="1" bordercolor="0000CC">'); document.write('<th align="center">Test</th>'); document.write('</table></center>'); document.write('<center><table width="100%" border="1" bordercolor="0000CC">'); document.write('<th align="center">Name</th><th align="center">Surname</th><th align="center">Age</th>'); var Name = "John"; var Type = "Mc"; var Version = "5"; document.write('<tr align="center"><td>' + Name + '</td><td>' + Type + '</td><td>' + Version + '</td</tr>'); document.write('</table></center>'); document.write('<center><caption>Table: Test</caption></center>'); }
it might be parsing document.write(test()); before it sees the functions, so put that after you declare the function
I Also meant to say that even if i take all the information out of the function : eg document.write(test()); function test() { } I still get undefined error under the heading and then next table with the information and under captain 'undefined'
try it like this: function test() { } document.write(test()); the browser needs to load the function first
Thanks IBalance for the quick reply, i tried what you suggested function test() {} document.write(test()); Sorry no Joy, still the information is in the table and after the captain 'undefined' is still sitting there but thanks again
ahh, cant document.write a function try something like this: <script type="text/javascript"> function test() { document.write('hello'); } test(); </script>
i'm not sure on this but could it have something to do with trying to pass a function filled with document.write()'s to the document.write()? what if you set it up like this? function test() { ... } bodyonload = test();
I should have expalained that i was using a external js script so i couldn't use javascript tags. The solution that Jamie18 suggested was 3 quaters there, Firstly i was calling the js script for the head of my html page, i moved this to the body to come in line with Jamie18's suggestion to use bodyonload = test(); instead of document.write(test()); But when i placed bodyonload = test(); after the function no information appeared so i placed it before the function like so: bodyonload = test(); function test() {} And this worked great Thanks for you help Ibalance and Jamie18.