Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2006, 12:16 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare select box

Hi,

I have the next problem.

I have a pulldown menu with value's in them.

duplicate pulldown menu's can be added unlimited times with a javascript button.

something like this:
Code:
<select>
  <option value="1">
  <option value="2">
  <option value="3">
</select>
<select>
  <option value="1">
  <option value="2">
  <option value="3">
</select>
<select>
  <option value="1">
  <option value="2">
  <option value="3">
</select>
Now i like to filter so that for example value 1 cant ben selected twice.

Hope this story is clear.

thnx

__________________________________________________ ________
This is my junk I'm gona eat it
 
Old March 23rd, 2006, 03:21 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Dj Kat!!
Plz try this

<SCRIPT>
function chk(index)
{
if(isMatchFound())
{
alert("Matches Found")
document.myform.sel[index-1].selectedIndex=0
}

}
function isMatchFound()
{
obj=document.myform.sel
str="=="
for(i=0;i<obj.length;i++)
{
indexat=document.myform.sel[i].selectedIndex
        if(indexat>0)
        {
            indexval=document.myform.sel[i].options[indexat].value
            str=str+indexval+"=="
        }
}

strArr=str.split("==")
if(strArr.length<4)
{
return false;
}
tempstr=str
for(i=1;i<strArr.length-1;i++)
{
    str=tempstr
    regexpstr="=="+strArr[i]+"=="
    str=str.substring(str.indexOf(regexpstr)+regexpstr .length-2,str.length)
    if(str.indexOf(regexpstr)>-1)
    return true
}
return false
}
</SCRIPT>
<form name="myform">
<select name="sel" onchange="chk(1)">
<option value="0">Select Option A </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel" onchange="chk(2)">
<option value="0">Select Option B </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel" onchange="chk(3)">
<option value="0">Select Option C </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel" onchange="chk(4)">
<option value="0">Select Option C </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel" onchange="chk(5)">
<option value="0">Select Option E </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
</form>
Hope this will help you :)

Cheers :)

vinod
 
Old March 25th, 2006, 05:44 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This works great thnx

__________________________________________________ ________
This is my junk I'm gona eat it
 
Old October 31st, 2007, 08:54 AM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to do the same thing and had a few additional issues. All your select boxes are named the same. I'd like to be able to name them sel1, sel2, sel3, sel4, sel5, etc. I also need to compare the drop downs against hidden fields, they would be named the same. So I would have the following form and not want to allow duplicates:

<form name="myform">
<input type="hidden" name="sel1" value="1">
<select name="sel2">
<option value="0">Select Option A </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel3">
<option value="0">Select Option B </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel4">
<option value="0">Select Option C </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<select name="sel5">
<option value="0">Select Option C </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<input type="hidden" name="sel6" value="5">
<select name="sel7">
<option value="0">Select Option E </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
</form>

 
Old November 15th, 2007, 11:03 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii MillerTime

ofcourse you can do this,
in this case u need to put sel1, sel2 etc in the code.and you can compare with hidden sel6 value.
if possible can you tell us where is exactly u getting problem.


Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Variey item in list box limit quatitiy and compare apple88 Classic ASP Databases 0 June 18th, 2007 02:25 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
compare the values in a select box ayse1st BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 January 7th, 2006 03:58 PM
multicolored List Box or Select Box sasidhar79 Javascript 1 February 15th, 2005 01:47 AM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.