473,608 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple select

Hello,
I would appreciate any assistance you have with the following
problem:

I have (as an example) an array of values as follows:
arrayvalues=new Array("0001","0 003","0005") where each is the value
of an option in a select statement:

<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>

Based on my array values I would like to highlight each option whose
value cooresponds to an element of my array. I have the following
javascript code:

usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}

Problem: Script will not highlight all options associated with my
array values. However, if I add an alert statement before or after
the if statement, the script will highlight each entry as needed.
Does anyone have any ideas on why this is happening?
Jul 31 '06 #1
4 2457

Matt Ratliff wrote:
Hello,
I would appreciate any assistance you have with the following
problem:

I have (as an example) an array of values as follows:
arrayvalues=new Array("0001","0 003","0005") where each is the value
of an option in a select statement:

<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>

Based on my array values I would like to highlight each option whose
value cooresponds to an element of my array. I have the following
javascript code:

usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}

Problem: Script will not highlight all options associated with my
array values. However, if I add an alert statement before or after
the if statement, the script will highlight each entry as needed.
Does anyone have any ideas on why this is happening?
I used the follwing to try to repeat the problem (based on assumptions
of your code fragments):

<script>
var arrayvalues=new Array("0001","0 003","0005");

function setSelects(){
usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}
}
window.onload=s etSelects;
</script>

<form>
<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>
</form>

However, it appears to work as you want it to (Firefox
1.5.05/Linux/Win2k & IE6).
Maybe the problem is how you are starting the script ?

Being one of those types who prefers to avoid nested loops, let me
suggest a little change to the script:
function setSelects(){
var inverted = new Array();
for(var i=0; i<arrayvalues.l ength; i++){
inverted[arrayvalues[i]] = true;
}

usertypes=docum ent.getElementB yId("usertypes" );
for(var i=0; i<usertypes.opt ions.length; i++)
{
var curOpt = usertypes.optio ns[i];
curOpt.selected = inverted[curOpt.value];
}
}

Jul 31 '06 #2
On 31 Jul 2006 08:04:06 -0700, "Paul" <pa********@gma il.comwrote:
>
Matt Ratliff wrote:
>Hello,
I would appreciate any assistance you have with the following
problem:

I have (as an example) an array of values as follows:
arrayvalues=new Array("0001","0 003","0005") where each is the value
of an option in a select statement:

<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>

Based on my array values I would like to highlight each option whose
value cooresponds to an element of my array. I have the following
javascript code:

usertypes=docu ment.getElement ById("usertypes ");
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}

Problem: Script will not highlight all options associated with my
array values. However, if I add an alert statement before or after
the if statement, the script will highlight each entry as needed.
Does anyone have any ideas on why this is happening?
I used the follwing to try to repeat the problem (based on assumptions
of your code fragments):

<script>
var arrayvalues=new Array("0001","0 003","0005");

function setSelects(){
usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}
}
window.onload= setSelects;
</script>

<form>
<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>
</form>

However, it appears to work as you want it to (Firefox
1.5.05/Linux/Win2k & IE6).
Maybe the problem is how you are starting the script ?

Being one of those types who prefers to avoid nested loops, let me
suggest a little change to the script:
function setSelects(){
var inverted = new Array();
for(var i=0; i<arrayvalues.l ength; i++){
inverted[arrayvalues[i]] = true;
}

usertypes=docum ent.getElementB yId("usertypes" );
for(var i=0; i<usertypes.opt ions.length; i++)
{
var curOpt = usertypes.optio ns[i];
curOpt.selected = inverted[curOpt.value];
}
}
Paul:
Thanks for the response. I agree about the nested loops. My
actual code doesnt use nested loops but I wanted to try and describe
the problem in a way that could be more easily understood. Here is my
actual code snippet:

say '<script language="javas cript">'
say 'opts=parent.do cument.getEleme ntById("misc3") ;'
do zz=1 to xref4s~items
say 'opts.options['xref4s[zz]['FARMTYPEUID']-1'].selected=true; '
end
say '</script>'

xref4s is a server side array where xref4s[1]['FARMTYPEUID']
contains "0001" for example. My form data is passed to a hidden
iframe that contains the above code. The resulting code from the
script will look like:

opts.options[1].selected=true
opts.options[3].selected=true
opts.options[5].selected=true

when my xref4s array contains ("0002", "0004", "0006")

The strange thing is the fact that if I add an alert inside the do
loop then it properly selects all related options.

Jul 31 '06 #3

Matt Ratliff wrote:
On 31 Jul 2006 08:04:06 -0700, "Paul" <pa********@gma il.comwrote:

Matt Ratliff wrote:
Hello,
I would appreciate any assistance you have with the following
problem:

I have (as an example) an array of values as follows:
arrayvalues=new Array("0001","0 003","0005") where each is the value
of an option in a select statement:

<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>

Based on my array values I would like to highlight each option whose
value cooresponds to an element of my array. I have the following
javascript code:

usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}

Problem: Script will not highlight all options associated with my
array values. However, if I add an alert statement before or after
the if statement, the script will highlight each entry as needed.
Does anyone have any ideas on why this is happening?
I used the follwing to try to repeat the problem (based on assumptions
of your code fragments):

<script>
var arrayvalues=new Array("0001","0 003","0005");

function setSelects(){
usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}
}
window.onload=s etSelects;
</script>

<form>
<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>
</form>

However, it appears to work as you want it to (Firefox
1.5.05/Linux/Win2k & IE6).
Maybe the problem is how you are starting the script ?

Being one of those types who prefers to avoid nested loops, let me
suggest a little change to the script:
function setSelects(){
var inverted = new Array();
for(var i=0; i<arrayvalues.l ength; i++){
inverted[arrayvalues[i]] = true;
}

usertypes=docum ent.getElementB yId("usertypes" );
for(var i=0; i<usertypes.opt ions.length; i++)
{
var curOpt = usertypes.optio ns[i];
curOpt.selected = inverted[curOpt.value];
}
}

Paul:
Thanks for the response. I agree about the nested loops. My
actual code doesnt use nested loops but I wanted to try and describe
the problem in a way that could be more easily understood. Here is my
actual code snippet:

say '<script language="javas cript">'
say 'opts=parent.do cument.getEleme ntById("misc3") ;'
do zz=1 to xref4s~items
say 'opts.options['xref4s[zz]['FARMTYPEUID']-1'].selected=true; '
end
say '</script>'

xref4s is a server side array where xref4s[1]['FARMTYPEUID']
contains "0001" for example. My form data is passed to a hidden
iframe that contains the above code. The resulting code from the
script will look like:

opts.options[1].selected=true
opts.options[3].selected=true
opts.options[5].selected=true

when my xref4s array contains ("0002", "0004", "0006")

The strange thing is the fact that if I add an alert inside the do
loop then it properly selects all related options.
Ahh, now that is more informative. I suspect that the javascript is
executing before the browser has built the references to the html
components. Using the javascript console on Mozilla/Firefox should
confirm this.
Try wrapping that up in a function called after the page loads.

Jul 31 '06 #4
On 31 Jul 2006 10:14:55 -0700, "Paul" <pa********@gma il.comwrote:
>
Matt Ratliff wrote:
>On 31 Jul 2006 08:04:06 -0700, "Paul" <pa********@gma il.comwrote:
>
Matt Ratliff wrote:
Hello,
I would appreciate any assistance you have with the following
problem:

I have (as an example) an array of values as follows:
arrayvalues=new Array("0001","0 003","0005") where each is the value
of an option in a select statement:

<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>

Based on my array values I would like to highlight each option whose
value cooresponds to an element of my array. I have the following
javascript code:

usertypes=docu ment.getElement ById("usertypes ");
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}

Problem: Script will not highlight all options associated with my
array values. However, if I add an alert statement before or after
the if statement, the script will highlight each entry as needed.
Does anyone have any ideas on why this is happening?
I used the follwing to try to repeat the problem (based on assumptions
of your code fragments):

<script>
var arrayvalues=new Array("0001","0 003","0005");

function setSelects(){
usertypes=docum ent.getElementB yId("usertypes" );
for(var j=0; j<arrayvalues.l ength; j++)
for(var i=0; i<usertypes.opt ions.length; i++)
{
if(usertypes.op tions[i].value==arrayva lues[j])
usertypes.optio ns[i].selected=true;
}
}
window.onload= setSelects;
</script>

<form>
<select id="usertypes" multiple="multi ple">
<option value="0033">da ta1</option>
<option value="0025">da ta2</option>
<option value="0001">da ta3</option>
<option value="0003">da ta4</option>
<option value="1234">da ta5</option>
<option value="0005">da ta6</option>
</select>
</form>

However, it appears to work as you want it to (Firefox
1.5.05/Linux/Win2k & IE6).
Maybe the problem is how you are starting the script ?

Being one of those types who prefers to avoid nested loops, let me
suggest a little change to the script:
function setSelects(){
var inverted = new Array();
for(var i=0; i<arrayvalues.l ength; i++){
inverted[arrayvalues[i]] = true;
}

usertypes=docum ent.getElementB yId("usertypes" );
for(var i=0; i<usertypes.opt ions.length; i++)
{
var curOpt = usertypes.optio ns[i];
curOpt.selected = inverted[curOpt.value];
}
}

Paul:
Thanks for the response. I agree about the nested loops. My
actual code doesnt use nested loops but I wanted to try and describe
the problem in a way that could be more easily understood. Here is my
actual code snippet:

say '<script language="javas cript">'
say 'opts=parent.do cument.getEleme ntById("misc3") ;'
do zz=1 to xref4s~items
say 'opts.options['xref4s[zz]['FARMTYPEUID']-1'].selected=true; '
end
say '</script>'

xref4s is a server side array where xref4s[1]['FARMTYPEUID']
contains "0001" for example. My form data is passed to a hidden
iframe that contains the above code. The resulting code from the
script will look like:

opts.options[1].selected=true
opts.options[3].selected=true
opts.options[5].selected=true

when my xref4s array contains ("0002", "0004", "0006")

The strange thing is the fact that if I add an alert inside the do
loop then it properly selects all related options.

Ahh, now that is more informative. I suspect that the javascript is
executing before the browser has built the references to the html
components. Using the javascript console on Mozilla/Firefox should
confirm this.
Try wrapping that up in a function called after the page loads.
Paul,
Okay, that did it. By adding the alert it must have given the
script the time it needed to reference the component. After the last
coorespondence I added this code which worked for the time being. It
used the same principle that you were reffering to, by waiting for the
script to complete:

call charout , 'window.onload += '
call charout , 'setTimeout('''
call charout , 'opts=parent.do cument.getEleme ntById("misc3") ;'
do zz=1 to xref4s~items
call charout , '
opts.options['xref4s[zz]['FARMTYPEUID']-1'].selected=true; '
end
call charout , ''',100)'
call charout , '0d0a'x

It built a string of the data, and passed it to the setTimeout
function to wait 100 ms. By appending it the window.onload it was
waiting until the load completed before processing the commands. I
really didnt even need the setTimeout function. The end result was as
you suggested. I replaced this with a function call invoked by the
windows onload event. Thanks for the help!
Jul 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7709
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2 when CH1 and CH2 have been choosen. $_GET gives me "CH2". Is there any way to get all the choosen channels elements? I would be very appreciative for any help. Thank you in anticipation. Regards
6
4284
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. Based on the number of variables passed through a GET string, I want to multiply the total number of selected items for each together to see how many possible combinations the selected items are generating. The following snippet of code...
6
7248
by: Adam Tilghman | last post by:
Hi all, I have found that IE doesn't seem to respect the <SELECT> "multiple" attribute when set using DOM methods, although the attribute/property seems to exist and is updated properly. Those changes just don't make it onto the screen. Am I doing something wrong here? If not, is there a better feature test I can use than "appName.match()"?
2
3645
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code" onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)" multiple="multiple" size="20">
2
3102
by: murraymiken | last post by:
I'm looking to have multiple multiple-select-boxes on a page. But I can only get the contents from the last selected value within a box, via PHP. I've tried numerous methods. What am I doing wrong? You can see ALL the values present in the url: http://myserver/test.php?notify_user_id%5B2%5D=1&notify_user_id%5B2%5D=2&notify_user_id%5B4%5D=2&notify_user_id%5B4%5D=3&notify_user_id%5B4%5D=4&notify_user_id%5B6%5D=4&btn_updcats=Update e.g. ...
1
5873
by: abhishekhs | last post by:
Hi all I have more than one multiple select lists in a page. Something like this <tr> <td> <select NAME="StrainList" ID="StrainList" SIZE="5" multiple="multiple" style="width: 150px"> <? for ($i=0; $i < $rows; $i++)
92
4684
by: bonneylake | last post by:
Hey Everyone, Well i was hoping someone could explain the best way i could go about this. i have a few ideas on how i could go about this but i am just not sure if it would work. Right now i have a form where you can add and delete multiple serial information. This works wonderful. But now for every serial information i add i need to be able to add and remove multiple parts to that serial. heres an example of what i mean serial...
58
8051
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast specification. But not sure what i am doing wrong. Here is what i am using to insert. All the sections...
482
27528
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
6
7553
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created the problem that when I went to select the other drop down menus, the selections i made on the multiple select one would clear. Then I had tried putting the multiple select menu last so that the selections wouldn't clear but then after clicking the...
0
8067
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6820
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.