Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 09-05-2009, 06:15 PM   #1 (permalink)
In The Zone
 
Sridhar_Rao's Avatar
 
Join Date: Feb 2007
Posts: 353
Default String matching in javascript


Guys, here is the situation. There are four elements in the form, let's say:
Code:
<input type="text" name="a1" id="a1">
<input type="text" name="a2" id="a2">
<input type="text" name="a3" id="a3">
<input type="text" name="a4" id="a4">
I want to ensure that data entered by the user is not identical in any of these elements. I mean no two elements can have same value. How can this be done in javascript with minimal coding?

Note: It is possible that one or more them may be left blank by the user.
__________________
Want to study M.Sc in any medical subjects? Read this www.microrao.com/msc.htm
Microx, a diagnostic microbiology laboratory software application www.labmicrox.com

Last edited by Sridhar_Rao; 09-05-2009 at 06:23 PM.
Sridhar_Rao is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 09-05-2009, 06:41 PM   #2 (permalink)
Super Hero - Super Powers
 
n2casey's Avatar
 
Join Date: Sep 2006
Location: Dynamic
Posts: 766
Cool Re: String matching in javascript

Below is simple solution for it.


Code:
    function CheckValues()
    {
        var avalues=new Array();
        var avalues[0]=document.getElementById('a1').value;
        var avalues[1]=document.getElementById('a2').value;
        var avalues[2]=document.getElementById('a3').value;
        var avalues[3]=document.getElementById('a4').value;
        
        for(i=0; i<avalues.length; i++)
        {
            for(j=0; j<avalues.length; j++)
                if(avalues[j] != '' && avalues[i] == avalues[j])
                    return false;
        }
        
        return true;
    }
Oops, I forgot the blank textbox part. Well now it's OK.
__________________
Minds are like Parachutes :arrow: They work best when open

Last edited by n2casey; 09-05-2009 at 09:03 PM.
n2casey is offline  
Closed Thread

Bookmarks

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


 
Latest Threads
- by Sujeet
- by gforz
- by soumya

Advertisement




All times are GMT +5.5. The time now is 03:12 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2