Repeating table with js?

This is a discussion on "Repeating table with js?" within the JavaScript Forum section. This forum, and the thread "Repeating table with js? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 24th, 2006, 16:54
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Repeating table with js?

Having some issues outputting this. Basically how it works is a user enters a number and when the button is clicked it repeats the html code based on the input integer. So since it is not displaying correctly etc I am obviously doing something wrong. javascript is not my strong point so any help would be appreciated. It also randomly generates numbers in the card based on a xml file's contents which works fine. The problem is I lose the formatting and only the first table is displayed although incorrectly.

Code:

Code: Select all
<script type="text/javascript">
document.write('<form name="generate"><input type=button value="Regenerate" onClick="gencards();"> <input type="text" name="printnumber" size="2" maxlength="3" /></form>')
function gencards() {
var burger = document.generate.printnumber.value
burger = burger -1;
i = 0;
while (i <= burger)
{
var str='';
var bingo='';
str='<table id="tbl1" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid" cellSpacing="0" cellPadding="0" border="0"><td class="heading">B<\/td><td class="heading">I<\/td><td class="heading">N<\/td><td class="heading">G<\/td><td class="heading">O<\/td><\/table>'
bingo='<script src="MeetingBingo.js" language="JScript"><\/script>'
document.write(str);
document.write(bingo);
i++
}
}
</script>
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 24th, 2006, 21:51
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Repeating table with js?

As your terminating value is known at the start of the loop, you should be using the for statement.

for (i=0; i <= burger; i++){

}

You code for printing the table definitions is missing the <tr> element. You are going <table><td>... instead of <table><tr><td>...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 24th, 2006, 22:04
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Woops heh yup you are right, I will try this tomorrow. Thanks!
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 25th, 2006, 12:43
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Ok so I got this:

Code: Select all
 function gencards() {
var burger = document.generate.printnumber.value
burger = burger -1;
var str='';
var bingo='';
str+='<table id="tbl1" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid" cellSpacing="0" cellPadding="0" border="0"><tr><td class="heading">B<\/td><td class="heading">I<\/td><td class="heading">N<\/td><td class="heading">G<\/td><td class="heading">O<\/td><\/tr><\/table>';
bingo+='<script src="MeetingBingo.js" language="JScript"><\/script>';
for (i=0; i <= burger; i++){
document.write(str);
document.write(bingo);
}
}
and the output is this not repeating and not building the table correctly so what am I missing? Wish I was as good at this as xhtml/css lol. If I could do this with PHP I would be fine but unfortunately they want it specifically done with 100% js. So there must be some issue with javascript outputting the html? Perhaps my logic is just screwed up.
Attached Images
File Type: jpg hmm.jpg (20.3 KB, 34 views)
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Jul 25th, 2006 at 12:47.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 25th, 2006, 14:15
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Repeating table with js?

Quote:
bingo+='<script src="MeetingBingo.js" language="JScript"><\/script>';
Why are you writing the above line after each table line?

Also you are saying the language is JScript and not JavaScript although it probable won't any difference with your code. JScript is IE specific.

If you could do a mock-up of what you are expecting to happen, I might get a better idea.

I don't think JavaScript requires you to escape the forward slashes, e.g., <\/tr> not required, </tr> will do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 25th, 2006, 14:19
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Yeah it only needs to work in IE, and you are probably right about the escaping of the tags. That script file is what generates the table. It makes a 5 x 5 table and randomly generates numbers from 1 - 75 in each cell. It needs to repeat as many tables as specified by the user so they can be printed and given out.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 25th, 2006, 15:52
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Repeating table with js?

So if you remove the backslashes and run the program, what is the current situation?

Are you saying the for loop only applies one iteration? If so I would look at the value being picked up for the number of repeats.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 25th, 2006, 16:04
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Well here it is currently.

1. The table is not getting displayed correctly and only repeats once
2. If I take off the escape on the js file call it breaks
3. If I remove the .js file call it repeats the BINGO table as many times as specified but not the 5x5 numbers grid
4. If I display the exact same code in the HTML document it displays normally but only once

I had it write out the value of genvalue which is the text field and it displayed it correctly.

Code: Select all
 function gencards() {
var genvalue = document.generate.printnumber.value
genvalue = genvalue -1;
var str='';
var bingo='';
str+='<table id="tbl1" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid" cellSpacing="0" cellPadding="0" border="0"><tr><td class="heading">B</td><td class="heading">I</td><td class="heading">N</td><td class="heading">G</td><td class="heading">O</td></tr></table>';
bingo+='<script src="MeetingBingo.js" language="javascript"><\/script>';
for (i=0; i <= genvalue; i++){
document.write(str);
document.write(bingo);
}
}
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jul 25th, 2006, 17:00
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Repeating table with js?

Copied your str+=... line into a blank html page, previewed the page and got a black border around the word BINGO, so the code without the '\' is correct and does work.

Are we maybe looking in the wrong area? Could it be something within the MeetingBingo.js file?

I note also that your bingo+=... line still has a '\' in it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jul 26th, 2006, 14:27
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Without escaping the bingo+ line it just cuts the script and outputs the js to the page. The linked .js file is what generates the table. If placed in the HTML it all works fine but only repeats once of course. The repeating bingo box should have 5 cells all with borders which is also not getting output correctly. Maybe this just won't work. I may convince them to let me use PHP or do it in asp.net.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jul 26th, 2006, 15:28
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

Attached is a shot of how it looks placed in the HTML.
Attached Images
File Type: jpg bingo.jpg (37.6 KB, 29 views)
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jul 27th, 2006, 13:08
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Repeating table with js?

k, almost got it working. I stripped the js code I needed from the external js file and it now repeats as expected. Just a few things to patch up and its good to go. Thanks for all of your help.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
repeating, table

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML repeating problems?? tails007 Web Page Design 8 Jan 18th, 2008 13:12
repeating background issues. Therealmatt Starting Out 4 Sep 20th, 2007 22:54
CSS repeating bg for button jwalker80 Web Page Design 3 Mar 1st, 2007 21:11
Repeating DIV in Safari chevy409 Web Page Design 0 Oct 4th, 2005 21:03


All times are GMT. The time now is 10:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42