473,574 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to lookup/compare a value in a table..

57 New Member
I have a table in a HTML form which has multiple rows, each row contains a user ID (too many to list on this forum).. The form has an input field at the top which the user types in a user ID, I want the form to compare this to the table. If there is a match to return true, if there is no match to return cancel.

I would user an onchange to call the javascript function.

Hope that's enough to go on, I shoul be able to modify any type of example to work... Basically though, it need to compare one field to the rows in the table and find a match.

Any suggestions greatly appreciated..
Sep 10 '07 #1
6 1901
acoder
16,027 Recognized Expert Moderator MVP
See this example.
Sep 10 '07 #2
iam_clint
1,208 Recognized Expert Top Contributor
or you can try to modify this code i made for reading tables like excel

http://www.thescripts.com/forum/thread646585.html
Sep 10 '07 #3
plumba
57 New Member
or you can try to modify this code i made for reading tables like excel

http://www.thescripts.com/forum/thread646585.html
Thanks for the suggestions but I'm still getting no joy.

I've now modified the page slightly, all the values are in a select box called 'userid'. The user then puts in an ID in a text box called '1stDefinition' '. The script should then se if the text entered in the 'existingid' field matches up to of the options in the 'userid' select box - regardless of which option is selected - it should make no difference as the select box will be hidden and is used only for this check.

The script I have so far is:

Expand|Select|Wrap|Line Numbers
  1. function compareID(){
  2.  
  3. var idlist = document.getElementById('1stDefinition').value;
  4. var idinput = document.getElementById('existingid');
  5.  
  6. alert(idlist);
  7. alert(idinput.value);
  8.  
  9. if (idlist == idinput.value){
  10.     alert("Match");
  11.     }else{
  12.     alert("No match");
  13.     }
  14.  
  15.  
  16. }
So you can see it only looks up the selected option in the '1stDefinition' select box - it should step through the whole lot to see if there is a match.

Regards
Sep 11 '07 #4
iam_clint
1,208 Recognized Expert Top Contributor
I think this is more what you was looking for

it loops through the options and compairs each value.
Expand|Select|Wrap|Line Numbers
  1. function compareID() {
  2. var idlist = document.getElementById('1stDefinition').options;
  3. var idinput = document.getElementById('existingid');
  4. var match = false;
  5. for (i=0; i<idlist.length; i++) {
  6.   if (idlist[i].value.toLowerCase() == idinput.value.toLowerCase()){ match = true;  }
  7. if (match) { alert("match"); } else { alert("no match"); }
  8. }
  9.  
Sep 11 '07 #5
plumba
57 New Member
I think this is more what you was looking for

it loops through the options and compairs each value.
Expand|Select|Wrap|Line Numbers
  1. function compareID() {
  2. var idlist = document.getElementById('1stDefinition').options;
  3. var idinput = document.getElementById('existingid');
  4. var match = false;
  5. for (i=0; i<idlist.length; i++) {
  6.   if (idlist[i].value.toLowerCase() == idinput.value.toLowerCase()){ match = true;  }
  7. if (match) { alert("match"); } else { alert("no match"); }
  8. }
  9.  
Hi, many thanks for that, the code seems to make sense but IE is throwing back an error saying that on a line in the form an object is expected, this line:

[HTML]<input type="button" onClick="compar eID();" value="Compare" >[/HTML]

That is the line which contains the button which calls the function and nothing else........ any sugestions??
Sep 11 '07 #6
iam_clint
1,208 Recognized Expert Top Contributor
Well the code i gave you works
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function compareID() {
  3. var idlist = document.getElementById('1stDefinition').options;
  4. var idinput = document.getElementById('existingid');
  5. var match = false;
  6. for (i=0; i<idlist.length; i++) {
  7.   if (idlist[i].value.toLowerCase() == idinput.value.toLowerCase()){ match = true;  }
  8. if (match) { alert("match"); } else { alert("no match"); }
  9. }
  10. </script>
  11. <input type="text" onblur="compareID();" value="" id="existingid"><select id="1stDefinition" name="1stDefinition"><option value="test">test</option><option value="apple">apple</option><option value="orange">orange</option></select>
  12.  
  13.  
theres my test page for it


So something your doing or something has changed.
Sep 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
10624
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays...
6
4704
by: dd_bdlm | last post by:
Hi this seems like a very simple thing to do but I am having no success. What I want to do is compare a value from a calculated field with a value from a table and then if it is in the table display another field in the table associated with it. ie I have a table of postcode 'starts' and a corresponding area ID code. I have a calculated...
4
4606
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have...
3
2410
by: Radu | last post by:
Hi. I have the following problem - I need to build a user-control in asp.net (an ascx) to somehow allow the users to search by first name or last name among a big (~10.000 records) email addresses database (SQL server table). I am thinking of allowing them to type something in EITHER the last name, EITHER the first name textbox, and on each...
0
8092
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8129
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6497
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5641
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2258
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1092
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.