Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 19th, 2005, 01:09 AM
SoC SoC is offline
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare values of several drop boxes, notify user

Hi,

I need to create a web page that shows 5 or more drop boxes. Their values will be populated from the same database.

I would like to alert the user when they select the same option in 2 or more drop boxes.

For example, if the user selects 'Pig' from box 1, 'Dog' from box 2, 'Pig' from box 3, the selected option in boxes 1 and 3 will change to red text, and an alert will pop up notifying them of the clash.

I can achieve this functionality across 2 drop boxes simply by comparing their values on the onChange event, but I'm not sure how to do it when their are more than 2 drop boxes.

Do I have to use an array or something? Any help much appreciated.

S

Reply With Quote
  #2 (permalink)  
Old April 21st, 2005, 10:17 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

This sort of works.


<html>

<head>
<title>Array Experiment</title>
</head>

<body>

<form name="form1">
<select name="sel1" id="1st" onchange="checkforduplicates()">
<option value="pig">Pig
<option value="dog">Dog
<option value="monkey">Monkey</option>
</select> <select name="sel2" id="2nd" onchange="checkforduplicates()">
<option value="dog">Dog
<option value="monkey">Monkey
<option value="pig">Pig</option>
</select> <select name="sel3" id="3rd" onchange="checkforduplicates()">
<option value="giraffe">Giraffe
<option value="Pig">Pig
<option value="zebra">Zebra</option>
</select> <select name="sel4" id="4th" onchange="checkforduplicates()">
<option value="wildebeest">Wildebeest
<option value="pigeon">Pigeon
<option value="Pig">Pig</option>
</select> <select name="sel5" id="5th" onchange="checkforduplicates()">
<option value="blackbird">Blackbird
<option value="pig">Pig
<option value="lemur">Lemur</option>
</select>
</form>

<script language ="javascript">
var timer1 = setTimeout("checkforduplicates()", 20)

function checkforduplicates(){

var checksel = {
checksel1 : document.form1.sel1,
checksel2 : document.form1.sel2,
checksel3 : document.form1.sel3,
checksel4 : document.form1.sel4,
checksel5 : document.form1.sel5
}


var holdingpen = new Array(checksel.checksel1.options(checksel.checksel 1.selectedIndex).value, checksel.checksel2.options(checksel.checksel2.sele ctedIndex).value, checksel.checksel3.options(checksel.checksel3.sele ctedIndex).value, checksel.checksel4.options(checksel.checksel4.sele ctedIndex).value, checksel.checksel5.options(checksel.checksel5.sele ctedIndex).value)



holdingpen.sort()

for (var i=0; i<holdingpen.length - 1; i++)
{
  if (holdingpen[i] == holdingpen[i+1])
    //holdingpen[i+1] = '';
    alert(holdingpen[i+1] = holdingpen[i] + ' was duplicated!');
    document.form1.reset();
}

}
</script>


</body>

</html>


Hope that helps
interrupt

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down boxes in Cells and selecting ranges tbmbob Excel VBA 0 June 1st, 2006 09:12 AM
Forms and drop down boxes Apocolypse2005 Javascript 1 December 6th, 2005 11:26 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Assigning Macros to Drop Down Boxes ashu_gupta75 Excel VBA 1 August 12th, 2004 12:44 AM
Two drop down dependent list boxes and a Button tcasp Classic ASP Basics 0 August 5th, 2003 02:06 PM



All times are GMT -4. The time now is 04:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.