tags:

views:

66

answers:

1

I have two html files information.html and employee.html.

Information.html contains two tables having IDs 'top' and 'bottom'. Employee.html is included in the <table id='top'> of information.html.

Employee.html's code, containing just a dummy <table>, is as follows:

<!-- employee.html -->
    <table align = "center" border="1" height="100px">
       <tr></b><td><b>No.</b></td><td><b>Name</b></td><td><b>Age</b></td></tr>

       <script type="text/javascript">
       var i =0;
       for (i= 0;i<20;i++)
       {
      document.write("<tr onclick= '---' ><td><b>" + i);             
        document.write("</b></td><td>Usman</td><td>56</td></tr>");
       }
       </script>
    </table>

When i open information.html in my browser, i see employee.html included in the <table id='top'> of information.html.

Now, what should i write in onclick (in the above code) so that when user click on a row in the table appearing in the 'top' table of information.html, some arbitrary text may appear in the <table id='bottom'> of information.html.

Please guide me.

Thanks

+1  A: 

You need to get the element on the page into which you want to insert the text, this is done using the getElementById function to get the element with id #bottom. Then you can use innerHTML to set the content of the table.

document.write("<tr onclick='document.getElementById(\"bottom\").innerHTML = \"some text\"'><td><b>" + i);

Don't forget the backslashes, otherwise you might find the quotes won't be escaped properly

James
It won't work because employee.html does not know "bottom" because bottom is in another html file titled information.html.
baltusaj
Not working.-- bottom -- is not visible to employee.html because table having id=bottom is in information.html, not in employee.html
baltusaj
How are you including the HTML files into the main page, is it an HTML include or are you doing it via a server-side language?
James
Its HTML include.
baltusaj
e.g. following line of code is used in information.html to include employee.html in the table having id 'top'.document.getElementById('top').innerHTML = '<iframe frameborder="1" src="'+url+'" width="727px" height="700px"></iframe>';where url contains the path of the employee.html
baltusaj
Try this: `document.getElementById('bottom').contentWindow.document.innerHTML = "some text";`
James