472,968 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,968 software developers and data experts.

Javascript --- synchronizing two select lists

I'm trying to keep the selected / displayed option of two different
select lists synchronized -- so when the user selects, say, the third
option on one of them, the third option on the other is displayed:

http://www.managerassistant.com/newpurchase.html

Here's the code I'm trying -- but that doesn't seem to work:

function synchronizeSelects(thisSelect,otherSelect)
{
// find the selected option in thisSelect
i = 0;
while(i < thisSelect.options.length &&
!(thisSelect.options[i].selected))
i++;

// if there is one, and it's not greater in # than
// the number of options in the otherSelect
if( (i != thisSelect.options.length)
&& (i < otherSelect.options.length) )
{
//then search the otherSelect for a selction
//and turn it off
for(j = 0; j < otherSelect.options.length; j++)
{
otherSelect.options[j].select = false;
otherSelect.options[i].defaultSelected = false;
}
//and then select i
otherSelect.options[i].select = true;
otherSelect.options[i].defaultSelected = true;
}
}

It's called from an onchange even on both selects. For example:
<select name="product" id="prod" class="smallselects"
onchange="synchronizeSelects(this,document.getElem entById('supp'))">

Any ideas what I may be doing wrong here?

Thanks,

Weston

~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
2 2841
Weston C wrote:
I'm trying to keep the selected / displayed option of two different
select lists synchronized -- so when the user selects, say, the third
option on one of them, the third option on the other is displayed:

http://www.managerassistant.com/newpurchase.html

Here's the code I'm trying -- but that doesn't seem to work:

function synchronizeSelects(thisSelect,otherSelect)
{
// find the selected option in thisSelect

....
function synchronizeSelects(thisSelect,otherSelect){
otherSelect.selectedIndex= thisSelect.selectedIndex;
}

<select name="product" id="prod" class="smallselects"
onchange="synchronizeSelects(this,this.form.supp)" >

<select name="supp" id="supp" class="smallselects"
onchange="synchronizeSelects(this,this.form.produc t)">

Mick
Jul 23 '05 #2
Try this:

<script type="text/javascript">
function syncSelect( first, second ) {
var first = (typeof first == "string") ? document.getElementById(
first ) : first;
var second = (typeof second == "string") ? document.getElementById(
second ) : second;
second.selectedIndex = first.selectedIndex;
}
</script>

<select id="one" onchange="syncSelect(this, 'two')">
<option>one</option>
<option>two</option>
<option>three</option>
</select>

<select id="two" onchange="syncSelect(this, 'one')">
<option>one</option>
<option>two</option>
<option>three</option>
</select>

should work..

Regards
Jan
Jul 23 '05 #3

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

Similar topics

3
by: Keith Veleba | last post by:
Hello to all fellow c.l.p'ers! Long-time listener, first-time caller. Background: I'm working on a project where I have to do some serious multithreading. I've worked up a decorator in Python...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
5
by: suslikovich | last post by:
Hi everyone, I have a problem synchronizing two list boxes on a form. I want to display information in the second box based on the selection in the first box. First box (List0)lists all company...
2
by: Christopher D. Wiederspan | last post by:
We are getting ready to move an ASP.NET application off of a single development machine and onto a "webfarm". Basically our webfarm is a bunch of identical servers with the load-balancing provided...
26
by: wardy | last post by:
Hi all, looking for a little bit of help.....I'm currently in the process of trying to understand the impact of the 508 guidelines on a web site that I am involved with, and I have a question...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
2
by: smartic | last post by:
i'm having three lists when i select from any one the others be visible by hierarchy but it takes to long to write my code is there is another away to write this code like XML that is my javascript...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.