Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output to a table 1

Status
Not open for further replies.

OnAFan

Technical User
Mar 13, 2002
120
US
Hello Everyone. Can someone please show me how I would make the following script output to a table vs. a textbox? Output would be a label and a value. Thanks in advance.

<SCRIPT>
function getSelectedValues (select) {
var r = new Array();
for (var i = 0; i < select.options.length; i++)
if (select.options.selected)
r[r.length] = select.options.value;
return r;
}

</SCRIPT>
//////////////////////////////////////////
<INPUT TYPE=&quot;text&quot; NAME=&quot;output&quot; SIZE=&quot;50&quot;>

<input type=&quot;button&quot; value=&quot;Add your selections&quot; ONCLICK=&quot;this.form.output.value = getSelectedValues
(this.form.select2);&quot;>
 
Thanks for your help, Sorry I am not real familiar with Javascript. I now have the script that generates a table using the DOM, but I am unsure how to link my data to this table. And this table shows up before I select any data in my drop down (source of data.) Any suggestions? Thanks,
Terry
 
This example uses an array to generate a table
maybe something like this is your solution....

<html>
<head>
<title></title>
<script language=&quot;JavaScript&quot;>
var text = new Array(&quot;label1&quot;,&quot;value1&quot;,
&quot;label2&quot;,&quot;value2&quot;,&quot;label3&quot;,&quot;value3&quot;);
</script>
</head>
<body>
<h2>After this that</h2>
<script language=&quot;JavaScript&quot;>
document.write (&quot;<table width='260' border='1' align='center'>&quot;)
for(i=0;i<text.length;i++) {
document.write (&quot;<tr><td>&quot; + text[i++] + &quot;</td>&quot;);
//^^ i++ here because you have pairs ^^
document.write (&quot;<td>&quot; + text + &quot;</td></tr>&quot;); }
document.write (&quot;</table>&quot;);
</script>
</body>
</html>

2b||!2b
 
Thanks LrnMore!!! Just what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top