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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down Box

Status
Not open for further replies.

LCD

MIS
Feb 19, 2001
72
US
I need to be able to use a drop down box to select a name, and from that name, have a field populated with a associated number for that name. The drop down box is currently setup to pull from a text file on the server and list about 3000 names, each name has a individual number. Is there a way to make the name that is chosen to have it's number show up preferably in a submitable label or text box? It doesn't matter if the number is hidden or not. ANY HELP IS MUCH APPRECIATED! Thank you
LCD
 
Hi LCD!
You should create an array and to fill it with all associated numbers.

numbArray = new Array(24, 364, 51, ..... );

Then, when user selects a name, there should be a call of a function that search a number associated to the selected name. Something like that:

for (i=0; i <= numbArray.length; i++)
{
if ( numbArray = yourForm.yourSelect.options.selectedIndex )
yourForm.yourTextfield.value = numbArray
}

That's all.
Enjoy!

Andrew | starway@mail.com
 
will that assign a number to the name (starting with 1)?
The names unfortunatly allready have 14 digit numbers allready assigned to them.
 
I greatly appreciate your help on this. Unfortunatly I am not a programmer, a just kinda muddle my way through this. (all I'm familiar w/ is a little Qbasic and a little html.) I'm having a little trouble w/ this.
I'm providing a bit of the code I'm working with here

I realize that a resolution to this problem is ALOT to ask for. But if anyone has any ideas, or can say atleast that it can't be done.

note: $ProejectFieldList$ refers to a .txt file filled with a list of client names located on the server. (the text field can be modified if required to make this work) This program has a .dat file that has references for all the $$ The bigest problem is that the text file with client names and numbers needs to be updated constantly by someone who has no idea how to add info into a html document.

<!-- Row12 //-->

<tr ID = &quot;VRow12&quot;>
<td valign=&quot;top&quot; bgcolor=&quot;#$$formBGColor&quot; align=&quot;right&quot; width=150><div ID = &quot;Row12&quot;><nobr><b>Project</b></nobr></div></td>
<td width=5>&nbsp;&nbsp;&nbsp;</td>
<td width=150 valign=&quot;top&quot;>
<select size=&quot;1&quot; name=&quot;Project&quot; ID=&quot;Project&quot;>
<option value=&quot;--&quot; selected></option>
$ProjectFieldList$
</select>
</td>
</tr>

<!-- Row12 End //-->

<!-- Row13 //-->

<tr ID = &quot;VRow13&quot;>
<td valign=&quot;top&quot; bgcolor=&quot;#$$formBGColor&quot; align=&quot;right&quot;><div ID = &quot;Row13&quot;><nobr><b>P.O.
Number</b></nobr></div></td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td valign=&quot;top&quot;><input type=&quot;text&quot; name=&quot;PONumber&quot; ID=&quot;PONumber&quot; size=&quot;30&quot; value = &quot;$$PONumberDefault&quot;
maxlength=&quot;79&quot;></td>
</tr>

<!-- Row13 End //-->

Here is a sample of the text file

big shot somebody,01235284563547
client someone,12345678901234
client someone else,00123456789012
das client,23456789012361
das other client,45678901237123
the lemmings,25484756241544

I thought I might have seen somthing out there that would have made this doable if in the text file, the &quot;,&quot; was replaced with &quot; -- &quot; or somthing, but that was awhile ago, before this challange came up.

If your confused by this, welcome to my world, just sit back and laugh with me.

THANK YOU FOR YOUR HELP
 
what is your problem exactly ???
-> populating a text box with the number associated to the name ? then Andrew gave you the best solution (you only have to populate your array with the values that are in the text file)
-> reading the text file ? then i don't know if this is the correct forum ...
-> updating the text file ? then it'sthe same as above ....
 
The problem is that I don't understand his answer, or howto put it into my html file. Like I stated before I am not a programer/designer. I could setup a enterprise wide network before I could write a &quot;hello world&quot; program. I appologize for my ignorance in the coding world.
What he has is as followed

numbArray = new Array(24, 364, 51, ..... );

for (i=0; i <= numbArray.length; i++)
{
if ( numbArray = yourForm.yourSelect.options.selectedIndex )
yourForm.yourTextfield.value = numbArray
}

where exactly does this go?

does &quot;yourForm&quot; = the name of my HTML file?

is this right?
<input type=&quot;text&quot; name=&quot;PONumber&quot; ID=&quot;PONumber&quot; size=&quot;30&quot; value = numbArray>

should I use &quot;numbArray&quot; or change it to somthing like &quot;ponumberArray&quot; ?

-Confused Admin
 
i answered this one on the js forum - we'll get thru this !!
 
OK LCD, don't be confused!
I'll try to explain you what happens here.

big shot somebody,01235284563547
client someone,12345678901234
client someone else,00123456789012
das client,00123456789012
das other client,45678901237123
the lemmings,25484756241544

Left part of each pair is a value of OPTION items of your <select>. Rigth part - the numbers you have to associate with the left part.
My suggestion was to create an array of numbers:

numbArray = new Array(,01235284563547
, 00123456789012, 00123456789012, ..... );

&quot;numbArray&quot; is just a name of JavaScript variable and of course you can change it.

The main condition is that all numbers you enter are in the same order as their names from left.

OPTOIN items are also the elements of an array (another one, it is created automatically), and every element has it's position number named index.

So all we have to do is to find the number that is associated with name. It can be done by comparison of their indexes.
This is done here by creating a function:

function FindNumber() {
for (i=0; i <= numbArray.length; i++)
{
 if ( numbArray = yourForm.Project.options.selectedIndex )
 yourForm.PONumber.value = numbArray
}
}

all this should be placed in in <HEAD> section of your HTML file:

<html>
<head>
...
<script language=&quot;javascript&quot;>
<!--
numbArray = new Array(,01235284563547
, 00123456789012, 00123456789012, ..... );

function FindNumber() {
for (i=0; i <= numbArray.length; i++)
{
 if ( numbArray = yourForm.Project.options.selectedIndex )
 yourForm.PONumber.value = numbArray
}
}
//-->
</script>
...
</head>
<body>
...
</body>
</html>


Important!
<select> and <textarea> fields sould be inside <form> ... </form> tag. I don't see it in your code.
&quot;yourForm&quot; is a name of a form:
<form name=&quot;yourForm&quot;> and you can change it too. If form name is not specified, you have to change &quot;yourForm&quot; to forms[0], if it is the only form you have on your page. If there are some of them, change [0] to the number of it's appearance (starting from zero).

Also, you should call FindNumber() function somehow. You should add a small part to your SELECT:

<select size=&quot;1&quot; name=&quot;Project&quot; ID=&quot;Project&quot; onChange=&quot;FindNumber()&quot;>

One more point. This system of number storage is static, and I think that you prefer something with databases. This is completely another story and I don't open it here. But if you manage to do it and afterwards create an array as I told, it will work good as well.

That's all if I'm not mistaken.
Hope it'll help you. But the better idea is to show all this to someone who knows a little bit the subject in order to modity/adapt everything to your specific needs.

Andrew | starway@mail.com
 
hey andrew, i gave almost the same solution but this :
function FindNumber() {
if (yourForm.Project.options.selectedIndex!=-1)
yourForm.PONumber.value = numbArray[yourForm.Project.options.selectedIndex]
}
seems more logical ;]


 
To iza:
Yes, maybe. I also missed an error in my comparison statement!
Almost got crazy white writing an explanation to all this.

Nice to hear from a professional on this list!

Andrew | starway@mail.com
 
the funniest is that while you were writing this here, i was trying to explain the SAME on the jscript forum (where the thread is also) ! LCD won't complain (s)he gets no help, (s)he gets twice the same !!!
(and yes i spotted the == being =, but to my mind, we're not here to give the whole proper code but rather general guidelines - i mean, if you're always given solution without having to think, you'll keep asking !)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top