problem changeing values in drop down box

B

Beemer Biker

I cant seem to change the values in my drop down box.
There are 3 items each has an associated value

name value
----------- -----------
MyDocuments "my documents"
Desktop "my desktop"
temp "c:\temp"

function SetWorkingList()
{
var SelectDestination

SelectDestination =document.getElementsByName('destination_select')
alert(SelectDestination[0].value) // this shows "my_documents" if
"MyDocuments" is selected
SelectDestination[0].value = "hi there"
}

I thought that [0] was the first item, [1] the second and [2] the third. I
thought wrong. Even if there are 3 items in the drop down box, the actual
length of SelectDestination is only 1 so [1] and [2] fail big time when I
try to subscript SelectDestination.

I cannot set the value "hi there". So how do I change the values on the
fly?

Eventually, when the form loads I want to fill in the values with the actual
desktop and my document paths. I know how to get those paths, but I cant
seem to figure out how to subscript into the dropdown box.

Looking at the code, I see functions such as FP_getObjectByID(id,n) Not
sure where that came from, FP2003 must have thought I needed it. Maybe
there is an FP_getObjectByNAME where I can get the drop-down box object and
fondle it all I want?


--
=======================================================================
Beemer Biker joestateson at grandecom dot net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================
 
T

Trevor L.

Hi Beemer Biker,

Some answers at the bottom.

Beemer said:
I cant seem to change the values in my drop down box.
There are 3 items each has an associated value

name value
----------- -----------
MyDocuments "my documents"
Desktop "my desktop"
temp "c:\temp"

function SetWorkingList()
{
var SelectDestination

SelectDestination =document.getElementsByName('destination_select')
alert(SelectDestination[0].value) // this shows "my_documents" if
"MyDocuments" is selected
SelectDestination[0].value = "hi there"
}

I thought that [0] was the first item, [1] the second and [2] the
third. I thought wrong. Even if there are 3 items in the drop down
box, the actual length of SelectDestination is only 1 so [1] and [2]
fail big time when I try to subscript SelectDestination.

I cannot set the value "hi there". So how do I change the values on
the fly?

Eventually, when the form loads I want to fill in the values with the
actual desktop and my document paths. I know how to get those paths,
but I cant seem to figure out how to subscript into the dropdown box.

Looking at the code, I see functions such as FP_getObjectByID(id,n) Not
sure where that came from, FP2003 must have thought I needed it. Maybe
there is an FP_getObjectByNAME where I can get the drop-down
box object and fondle it all I want?

Do you really want to fondle it - perhaps it has become very dear to you
:))

I would need to see the HTML code as well as the JavaScript.

However,

This applies:
I thought that [0] was the first item, [1] the second and [2] the third.
only when SelectDestination is an array

If you have elements in text boxes, you need to name them
e.g.
<input type="text" id="select1" value="a" />
<input type="text" id="select2" value="b" />
<input type="text" id="select3" value="c" />

Then refer to them as:
var SelectDestination
SelectDestination = document.getElementById('select1')
alert(SelectDestination.value)
SelectDestination = document.getElementById('select2')
alert(SelectDestination.value)

But to avoid code repetition, you can put them into a for loop:
var SelectDestination
for (var i=1; i<10; i++) // set the 2nd parameter to 1 more than the maximum
value of i
{ SelectDestination = document.getElementById('select' + i)
alert( "select" + i + " Value=" + SelectDestination.value)
}

You can set the values as well by:
document.getElementById('select1').value = "hi there"
or again in a loop

Note that I use document.getElementById as this is what I am used to. I
think is becoming standard anyway.

There may be other ways to refer to the elements of a form as an array, but
this way works

Regrading FP_getObjectByID(id,n), this was no doubt set up by FP. It would
use document.getElementById, but it may also test for other browsers which
don't use document.getElementById - these are rare nowadays.
 
T

Trevor L.

Trevor said:
There may be other ways to refer to the elements of a form as an
array, but this way works

To refer to the elements of a form with id="formname" as an array, use
document.formname.elements

e.g. to display the value of element 0, use
document.formname.elements[0].value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top