?
Solved

insert document.write into a table column

Posted on 2001-07-10
5
Medium Priority
?
376 Views
Last Modified: 2010-05-18
The following code creates a table and uses document.write to fill the cells. How can I get the entire output to go into an existing table's column, the td with the id="gradeCELL" ?


<html>
<body>
<script LANGUAGE="JavaScript">
v1=1
v2=2
 document.write('<TABLE BORDER=1 WIDTH=10><TR></TR><TR><TD COLSPAN=3 ALIGN=CENTER><B>'
 +"Grade Report"+'</B><BR></TD></TR>');
 
 document.write('<TR><TD><B>'+ "w" +'</B></TD> <TD><IMG SRC="d.gif" HEIGHT=10 WIDTH='+(v1/(v1+v2)*50)
 +' BORDER=1></TD><TD>'+v1+'</TD></TR>'
 +'<TR><TD><B>'+ "r"+'</B></TD><TD><IMG SRC="c.gif" HEIGHT=10 WIDTH='+(v2/(v1+v2)*50)
 +' BORDER=1></TD><TD>'+v2+'</TD></TR>'+'<TR><TD><B>'+'</TD></TR>');
 
 document.write('<TR><TD COLSPAN=3 ALIGN=CENTER><B>'+"pct="+ Math.round(10*(v2/(v1+v2)*100))/10.0 +"%"
+'</B></TD></TR></TABLE>');
</script>



<div align="left">
  <table border="1" width="100%">
    <tr>
      <td id="gradeCELL" width="100%">&nbsp;</td>
    </tr>
  </table>
</div>



</body>
</html>
0
Comment
Question by:mathprof
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6271230
You can nest tables as follows:

<Table>
     <tr>
         <td>
             Cell 1
         </td>
         <td>
             <table>
                <tr>
                   <td>
                       Imbedded cell 1
                   </td>
                   <td>
                       Imbedded cell 2
                   </td>
                </tr>
              </table>
          </td>
      </tr>
</table>

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6271241
Using your examples above, I've embedded the table into the cell that you requested:

<html>
<body>
<div align="left">
 <table border="1" width="100%">
   <tr>
     <td id="gradeCELL" width="100%">

<script LANGUAGE="JavaScript">
v1=1
v2=2
document.write('<TABLE BORDER=1 WIDTH=10><TR></TR><TR><TD COLSPAN=3 ALIGN=CENTER><B>'
+"Grade Report"+'</B><BR></TD></TR>');

document.write('<TR><TD><B>'+ "w" +'</B></TD> <TD><IMG SRC="d.gif" HEIGHT=10 WIDTH='+(v1/(v1+v2)*50)
+' BORDER=1></TD><TD>'+v1+'</TD></TR>'
+'<TR><TD><B>'+ "r"+'</B></TD><TD><IMG SRC="c.gif" HEIGHT=10 WIDTH='+(v2/(v1+v2)*50)
+' BORDER=1></TD><TD>'+v2+'</TD></TR>'+'<TR><TD><B>'+'</TD></TR>');

document.write('<TR><TD COLSPAN=3 ALIGN=CENTER><B>'+"pct="+ Math.round(10*(v2/(v1+v2)*100))/10.0 +"%"
+'</B></TD></TR></TABLE>');
</script>
;</td>
   </tr>
 </table>
</div>
</body>
</html>


Is this what you mean?

Fritz the Blank
0
 

Author Comment

by:mathprof
ID: 6271626
Almost.

What I want to do is be able to dynamically insert the 3x3 table into the other table.

So, I want to be able to set the values of v1 and v2, then call the javascript (as a function)and have it put the 3x3 table into the other table.

Say we call the javascript Graph and then set v1, v2, then call graph.

Your code did OK, but the values of v1 and v2 will change.

Thanks!
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 200 total points
ID: 6272996
Ok, how about the following:

Function MakeCells(v1,v2)
{
document.write('<TABLE BORDER=1 WIDTH=10><TR></TR><TR><TD COLSPAN=3 ALIGN=CENTER><B>'
+"Grade Report"+'</B><BR></TD></TR>');

document.write('<TR><TD><B>'+ "w" +'</B></TD> <TD><IMG SRC="d.gif" HEIGHT=10 WIDTH='+(v1/(v1+v2)*50)
+' BORDER=1></TD><TD>'+v1+'</TD></TR>'
+'<TR><TD><B>'+ "r"+'</B></TD><TD><IMG SRC="c.gif" HEIGHT=10 WIDTH='+(v2/(v1+v2)*50)
+' BORDER=1></TD><TD>'+v2+'</TD></TR>'+'<TR><TD><B>'+'</TD></TR>');

document.write('<TR><TD COLSPAN=3 ALIGN=CENTER><B>'+"pct="+ Math.round(10*(v2/(v1+v2)*100))/10.0 +"%"
+'</B></TD></TR></TABLE>');
</script>
}


<div align="left">
 <table border="1" width="100%">
   <tr>
     <td id="gradeCELL" width="100%">
         <SCRIPT LANGUAGE=javascript>
          <!--
          =MakeCells(4, 2)
          //-->
         </SCRIPT>
     </td>
   </tr>
 </table>
</div>

In the above example, I called the function with the values 4 and 2, but I could call the function with any numeric values.

Is that what you wanted?
0
 

Author Comment

by:mathprof
ID: 6274175
Thanks,
Prof Weissman
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question