Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: dynamic dot notation?


Message #1 by "Charles Carter" <Charles.Carter@i...> on Thu, 22 Feb 2001 16:39:02
> Mark,
> 
> I am using only javascript and HTML. I am adding to a table with the DOM 
> insertRow method to dynamically add rows, therefore; the need to address 
> the new row,cell combination and/or in one cell i create a select object 
> and would like to get the selected value. 
> 
> As to your reply, I'm not familar with the forms(x) where x = ?
> 
> 
The forms(x) referred to is the forms array of the document object. To 
reference a form in your page using it, use: 
document.forms[0]...
document.forms[1]...
OR
give the forms name and id attributes and access the array using these 
instead:
document.forms['form1']...
document.forms['form2']...

EXAMPLE
<html>
<head><title>Forms</title></head>
<body>
<form id="form1" name="form1">
<select name="selectList" onChange="alert(document.forms
['form1'].selectList.options[document.forms
['form1'].selectList.selectedIndex].value)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>
</body>
</html>

Here, the form is referenced using:
document.forms['form1']
The select list option values are referenced by using the options array:
document.forms['form1'].selectList.options[...].value
And the array index of the currently selected option is given by:
document.forms['form1'].selectList.selectedIndex

Hope this helps (if it does, please let me know how you integrated it with 
your table creation DOM thing)

Peter

  Return to Index