Closed Thread Icon

Topic awaiting preservation: Selecting visible value - NOT absolute value... Pages that link to <a href="https://ozoneasylum.com/backlink?for=12605" title="Pages that link to Topic awaiting preservation: Selecting visible value - NOT absolute value..." rel="nofollow" >Topic awaiting preservation: Selecting visible value - NOT absolute value...\

 
Author Thread
Dufty
Paranoid (IV) Inmate

From: Where I'm from isn't where I'm at!
Insane since: Jun 2002

posted posted 02-04-2003 18:04

Hi again.
Having a little trouble working this one out, was hoping someone had experienced and cracked the problem:

I'm trying to auto populate a form field with the data from another field (a drop down list).
Ordinarily, not a problem:

code:
<script language="JavaScript">
function printVals(x) {
with (document.forms["myForm"]) {

var getIt1 = item1.value
var getIt2 = item2.value
var getIt3 = item3.value

if (x == 1) {
Show1.value = getIt1
Show2.value = getIt2
Show3.value = getIt3
}
}
}

etc...



However... the list I'm accessing is linked to a database, and I'm using Visible names, with actual values being an ID:

code:
<option value="ItemID">itemName</option>



For whatever reason, I can't figure out how to select the VISIBLE name, and show that on the page (for printing out).
The ID is then passed to the database and stored (got that bit cracked... just can't get my head around the other).


Please help!
Thanks again
Dufty

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 02-05-2003 10:49

More HTML/Javascript, but here's how you can loop a dropdown and pick what you need:

code:
<HTML>
<HEAD>
<TITLE>LoopDaDropBox</TITLE>

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;
function popEm(){
thing = document.forms[0].dropBox;
for(i=0;i<thing.length;i++){
alert(thing[i].value);
alert(thing[i].text);
}
alert("selected value is: " + thing.options.selectedIndex);
}
// -->
</SCRIPT>
</HEAD>

<BODY>

<FORM ACTION="#" >
<SELECT NAME="dropBox" onchange="popEm()">
<OPTION value="0"> - Select value - </OPTION>
<OPTION value="1">Value 1</OPTION>
<OPTION value="2">Value 2</OPTION>
<OPTION value="3">Value 3</OPTION>
</SELECT>
</FORM>

</BODY>
</HTML>



{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

Dufty
Paranoid (IV) Inmate

From: Where I'm from isn't where I'm at!
Insane since: Jun 2002

posted posted 02-05-2003 11:20

Nice code DmS, but unfortunately, it doesn't address my problem (or I can't see the answer at least).

Assume I select "Value 1"
Your output says: "selected value is: 1"
I need to capture the label, so it would say: "selected value is: Value 1"

I can already get the value, just can't work out how to capture the label.

I've even looked into applying the label property: <label for="ItemID">Item Name:</label>
But my drop-down is created on the fly (VBScript ASP) and this seems to be where I'm struggling.

&#0124; &#0124;EDIT&#0124; &#0124;
I don't believe it!
Took some working out, but I seem to have cracked this one:

code:
<script language="JavaScript">
function printVals(x) {
with (document.forms["myForm"]) {

var itemIndex = itemID.selectedIndex
var itemText = itemID.options[itemIndex].text


if (x == 1) {
itemShow.value = itemText

}
}
}
</script>

<input type="Button" onClick="printVals(1)">



It was a pain, but I had no idea that JavaScript accessed the element in such a roundabout way...
First get the index, then get the text that relates to that index, then print that text... sheesh!

Just took a little patience, (and google).

___________________________
Money is the game other people play, that I try to avoid by having just enough not to play it.
-Norman Mailer
[Dufty][Cell 698]

[This message has been edited by Dufty (edited 02-05-2003).]

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 02-05-2003 16:50

Okidoki, I sort o missed that you should pick the text of the one selected... doh

Ain't it fun to learn something new every day hopefully you got some clue from it anyways
/Dan


{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

Dufty
Paranoid (IV) Inmate

From: Where I'm from isn't where I'm at!
Insane since: Jun 2002

posted posted 02-06-2003 12:37

Indeed, it often seems to be the way:

Have a problem, can't find an answer.
Post problem on Asylum.
While thinking how to best word request, realise possible solution.
Go and play with idea.
Meanwhile - someone responds... a light blinks on...
Find answer and post it.
(Funny how so many people find their own solution after posting here)

Job done.

Thanks again

___________________________
Money is the game other people play, that I try to avoid by having just enough not to play it.
-Norman Mailer
[Dufty][Cell 698]

« BackwardsOnwards »

Show Forum Drop Down Menu