JavaScript onClick() Display

Posted by junaidkaps on Stack Overflow See other posts from Stack Overflow or by junaidkaps
Published on 2012-11-23T22:42:02Z Indexed on 2012/11/23 23:04 UTC
Read the original article Hit count: 200

I have an array consisting of several objects containing Strings. I am successfully able to display the array by using:

<td><p onclick="theMiddle(this)">The Middle</td>

As you see from the td tag this is part of a table. Issue is that the browser opens up a new page to display my text. I have been trying to display the array above my table in a p tag.

//JavaScript
var arrayTheMiddle = new Array (showName.theMiddle, beginingTime.theMiddle, 
network.abc, duration.thirty, rating.general, description.theMiddle, showImage.theMiddle);  

function theMiddle(obj){
   for(i=0; i < arrayTheMiddle.length; i++)
     {
      document.write(arrayTheMiddle[i] + "<br>");
     }
}

//HTML File

<p>Would like the array/function displayed here while the user clicks within the table below (entire table has not been listed)</p>

<td><p onclick="theMiddle(this)">The Middle</td>

Unfortunately I am constantly failing at utilizing get element by id to call my function which consists of an array. I have searched for all sorts of stuff, yet frankly I'm lost. Not even sure if my approach is correct at this point. I'm sure this is one of those simple things that are blowing over my head!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html