Cheers Spike Alex
-----Original Message----- From: Spike [mailto:[EMAIL PROTECTED]] Sent: 19 December 2002 15:19 To: [EMAIL PROTECTED] Subject: RE: [ cf-dev ] OT : Javascript Question I think the code below should do what you want: ################################################ Start of code ################################################ <script> function checkUnique(frm,fieldname) { // Initialize an array to hold the identically named select boxes var aFields = new Array(); var tmpArray = new Array(); // Strip the select boxes out of the form for (var i=0;i<frm.elements.length;i++) { if (frm.elements[i].name == fieldname) { aFields[aFields.length] = frm.elements[i].value; } } // Check if we found the select boxes in the form if (aFields.length) { // Loop over the select box values for (var i=0;i<aFields.length;i++) { // Loop over the values found so var // checking for duplicates for (var j=0;j<tmpArray.length;j++) { if(tmpArray[j] == aFields[i]) { alert('Duplicate values found in select boxes. The select boxes must have unique values'); return false; } } tmpArray[tmpArray.length] = aFields[i]; } } else { alert('Invlaid fieldname passed to checkUnique() function'); return false; } return true; } </script> <form action="#" method="post" onsubmit="return checkUnique(this,'box1')"> <select name="box1"> <option value="1">Option 1 <option value="2">Option 2 <option value="3">Option 3 </select> <select name="box1"> <option value="1">Option 1 <option value="2">Option 2 <option value="3">Option 3 </select> <select name="box1"> <option value="1">Option 1 <option value="2">Option 2 <option value="3">Option 3 </select> <input type="Submit" value="Test"> </form> <cfdump var="#form#"> ################################################ End of code ################################################ Spike Stephen Milligan Team Macromedia - ColdFusion Co-author 'Reality Macromedia ColdFusion MX: Intranets and Content Management' http://spikefu.blogspot.com > -----Original Message----- > From: Alex Skinner [mailto:[EMAIL PROTECTED]] > Sent: 18 December 2002 16:08 > To: [EMAIL PROTECTED] > Subject: RE: [ cf-dev ] OT : Javascript Question > > > The problem is all the selectboxes are called the same name > hence the need for a list function > > 1,2,3 > > 1,2,2 <--Error > > Alex > > -----Original Message----- > From: Matt Horn [mailto:[EMAIL PROTECTED]] > Sent: 19 December 2002 14:51 > To: [EMAIL PROTECTED] > Subject: Re: [ cf-dev ] OT : Javascript Question > > > Something like > > if((selectbox.value ==selectbox2.value) || (selectbox2.value > ==selectbox3.value) || (selectbox.value ==selectbox3.value)) { > > alert("please select unique values for each box"); > } > else { > formname.submit(); > } > > > I havnt tested this but it should work in IE at least > > > > At 14:20 18/12/2002 +0000, you wrote: > >Hi, > > > >Having one of those mind blank days > > > >I have 3 select boxes within a form all with the same name > > > > > >What I want to do is check to make sure that the user cant > select the > >same option more than once > > > >e.g. > > > >1,2,1 > > > >1,1,3 > > > >So that the form will only submit if the list is unique > > > >Anybody got any ideas (are there any list functions) or any code > >snippets > > > >got as far as > > > >if (document.NewConf.Category_ID.value.length){ > > > >} > > > >but now want to check each element of the list > > > >Any ideas > > > >Alex > > > > > > > >-- > >** Archive: > http://www.mail-archive.com/dev%> 40lists.cfdeveloper.co.uk/ > > > > >To unsubscribe, e-mail: > [EMAIL PROTECTED] > >For additional commands, e-mail: > [EMAIL PROTECTED] For > >human help, e-mail: [EMAIL PROTECTED] > > > -- > ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/ > > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] For human help, e-mail: > [EMAIL PROTECTED] > > > > > -- > ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/ > > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] For human help, e-mail: > [EMAIL PROTECTED] > > > -- ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] For human help, e-mail: [EMAIL PROTECTED] -- ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] For human help, e-mail: [EMAIL PROTECTED]
