473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

57
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 1889
acoder
16,027 Expert Mod 8TB
See this example.
Sep 10 '07 #2
iam_clint
1,208 Expert 1GB
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
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 Expert 1GB
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
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="compareID();" 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 Expert 1GB
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
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...
6
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...
4
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.