Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
accessing object elements from javascript
Old 03-02-2011, 07:25 PM accessing object elements from javascript
Skilled Talker

Posts: 83
Trades: 0
Code:
<script>
function addString() {
  var text = document.myform.selectOption.value;
  var testNode = document.getElementById('test');
  var newNode = document.createElement('b');
  newNode.setAttribute("id",text);
  newNode.innerHTML = text;
  testNode.appendChild(newNode);
}
</script>

<form name="myform" method="post" action="action">
<select name="selectOption">
    <option value="option1">option1</option>
    <option value="option2">option2</option>
    <option value="option3">option3</option>
</select>

<input name="Add1" type="button" class="formtext" value="Add"  onclick="addString();">

<p id="test"></p>
</form>
I'm using javascript to grab the value picked from a dropdown menu and populate it below, which it works fine with the code above.
The problem is that if I make the following change to the select name my javascript doesn't work anymore:

Code:
<script>
...
var text = document.myform.selectOption[0].option.value;
...
</script> 

<form>
<select name="selectOption[0].option">
...
</form>
I get an error saying that document.myform.selectOption.0 is null or not an object

How can I achieve the above using this sort of names, the name has to be this form, I cannot change it because they are an array of objects.

Thanks in advanced.
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
DmitryS is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-02-2011, 07:32 PM Re: accessing object elements from javascript
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
selectOption.option[0].value
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to accessing object elements from javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10069 seconds with 12 queries