Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javascript: looping thru elements to find duplicates

Reply
Thread Tools

javascript: looping thru elements to find duplicates

 
 
da_rod_father
Guest
Posts: n/a
 
      03-16-2006
Hi all,

I am entering text into an input field in my jsp, i want to check all
other input values to see if there is a duplicate. I am using the
getElementsByName method to do this because it returns a collection of
values specified by the name. My problem is when i enter in a new value
and check all other values, it always returns true. I want to compare
all element values with the new value I just entered. I am looking for
direction.

Can anyone help point me in the right direction?

 
Reply With Quote
 
 
 
 
Hal Rosser
Guest
Posts: n/a
 
      03-16-2006

"da_rod_father" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi all,
>
> I am entering text into an input field in my jsp, i want to check all
> other input values to see if there is a duplicate. I am using the
> getElementsByName method to do this because it returns a collection of
> values specified by the name. My problem is when i enter in a new value
> and check all other values, it always returns true. I want to compare
> all element values with the new value I just entered. I am looking for
> direction.
>
> Can anyone help point me in the right direction?
>


Boil your code down to a basic page that demonstrates the problem - and post
it here.
(What type of input fileds are you working with that have several with the
same name ? - ?Radio Buttons?)
usually, in javascript, you can access the field directly as :
document.formName.ElementName.value .
2
HTH


 
Reply With Quote
 
 
 
 
da_rod_father
Guest
Posts: n/a
 
      03-16-2006
The type of input fields are text and the reason that they have the
same name is that I am dynamically building the rows that the input
fields are in. They have the same name but different values. Here is
a snippet of code that I am working with. I only want to check for
duplicate values that are of the name="prop".


<script>

function setPropField(formField,indx,secName,header){

var frm = document.setPropertyForm;
frm.prop.value = formField.value;
frm.indx.value = indx;
frm.secName.value = secName;
frm.header.value = header;


thisProp = formField.value;
var dupeFrm = document.checkForPropDuplicatesForm;
var propVals = dupeFrm.document.getElementsByName("prop");




for( var i = 0; i < propVals.length; i++) {
thisElem = propVals[i].value;

if( thisProp == thisElem ) {
alert("This is a duplictae value" +
"\n Please create another" );
return false;
}

}

}

</script>


<% SortedMap props = (SortedMap) headers.get(sectionName);
Set set = props.keySet();
Iterator it = set.iterator();
Object pval = "";
Object vval = "";

while (it.hasNext()) {
pval = (Object) it.next();
vval = (Object) props.get(pval);
iii++;
%>


<tr>
<td colspan="4" width="100%">
<table class="summaryTable" width="100%">

<tr class="tableTitle" style="border:0px;padding:0px;">
<td colspan="4"><span class="style2">Add Property and
Value</span></td>
</tr>
<tr class="headerRow firstColor">
<td>ENV</td>
<td>Name</td>
<td>Value</td>
</tr>
<tr class="firstColor">
<td><strong>ADA</strong></td>
<td><input name="prop" id="prop" value="" size="50"
onchange="setPropField(this,'<%=iii %>','<%=sectionName %>','<%=header
%>');"></input></td>
<td><input name="propVal" id="propVal" value="" size="85"
onchange="setValField(this,'<%=iii %>','<%=sectionName %>','<%=header
%>');"></input></td>
</tr>
<tr>
<td colspan="3" align="right"><img onclick="submit();"
src="images/btnBigSave.gif"></td>
</table>
</td>
</tr>

<% } %>

 
Reply With Quote
 
Hal Rosser
Guest
Posts: n/a
 
      03-18-2006

Why not try giving each text box its own unique name - then accessing them
that way ?


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Order notes starting at C thru B rather than A thru G Max Williams Ruby 3 01-06-2009 11:37 AM
RDP thru Cisco VPN client and thru 501 Failure curttampa@gmail.com Cisco 21 08-26-2008 03:11 PM
Can't access Web Service thru DLL (but can thru Windows App) THTB ASP .Net Web Services 0 05-17-2007 06:43 PM
deleting vector elements while looping thru it kaferro@hotmail.com C++ 16 04-12-2007 12:25 PM
Looping thru all controls on a WebForm Craig G ASP .Net 5 02-22-2005 03:02 PM



Advertisments