simple enough I guess but I am a total newbie in this. I tried doing this in PHP but then reconsidered to do it in JS, so I need some help. The code:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function reply_click(clicked_id)
{
alert(clicked_id);
var basketItems=new Array();
//var i = 0;
basketItems[1] = clicked_id;
}
</script>
</head>
<body>
<table height="100%" width="80%" cellspacing="10" cellpadding="10" border="1">
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="shirt" value="shirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="pants" value="pants" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="socks" value="socks" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="dress" value="dress" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="skirt" value="skirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="topbody" value="topbody" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="sheets" value="sheets" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="pillowcover" value="pillowcover" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="blanket" value="blanket" style="width:200px; height:100px;" type="submit"/></td>
<tr>
</table>
<div style="width:18%; height:40%;position: absolute; top: 20px; right: 10px; border:2px solid;">
<script type="text/javascript">
var counter=0;
for (counter=0; counter<basketItems.length; counter++)
document.write(basketItems[counter] + "<br>");
</script>
</div>
<br><br><br>
Now what I expected to happen. I click the button, the alert comes out with button name clicked...then it adds that to list. Following it displays that list in the div tag. What happened wrong? it just displays the alert but nothing is shown in the div tag so am assuming something wrong with inserting to array or printing...
Thanks,
UPDATE: This code seems to work on jsfiddle but not on my broswer...any clue what different is there?
<html>
<head>
<title>Test</title>
<script type="text/javascript">
var basketItems = [];
function reply_click(clicked_id)
{
alert(clicked_id);
basketItems.push(clicked_id);
var html = '';
for(var i = 0; i < basketItems.length; i++) {
html += basketItems[i] + '<br/>';
}
document.getElementById('list').innerHTML = html;
}
</script>
</head>
<body>
<table height="100%" width="80%" cellspacing="10" cellpadding="10" border="1">
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="shirt" value="shirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="pants" value="pants" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="socks" value="socks" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="dress" value="dress" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="skirt" value="skirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="topbody" value="topbody" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input onClick="reply_click(this.name)" name="sheets" value="sheets" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="pillowcover" value="pillowcover" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input onClick="reply_click(this.name)" name="blanket" value="blanket" style="width:200px; height:100px;" type="submit"/></td>
<tr>
</table>
<div id="list" style="width:18%; height:40%;position: absolute; top: 20px; right: 10px; border:2px solid;">
</div>
</body>
</html>
and the JS fiddle link is: http://jsfiddle.net/fVQVy/ as posted here as a solution And thanks all for your patience...greatly appreciated....