Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript Comparison problem 1

Status
Not open for further replies.
Mar 19, 2002
3
US
I am a rookie at javascript so this may be a simple question.
If this doesn’t work, what am I missing? How do I get the code (RRH) from the page to equal the number value (78)? Is this not possible?

if(!found)
{
var salesman = document.getElementById('salesman1');
var code = salesman.innerHTML; // Salesman ex. RRH
var RRH = 78;
var DRH = 78;
var BJS = 78;
var SLA = 91;
var MDT = 84;
var CBC = 81;
var CWS = 85;
var TAB = 90;
var MWM = 88;
// RRH == 78 // example
if(code == currentUserId) // These aren’t matching. Any Idea what I am missing?
{
found = true;
alert('Match = ' + found);
}
}
 
Hard to say without a bit more info, but as a guess, and since you are using the innerHTML attribute of an element with an ID of salesman1, one has to wonder what else may be inside that element?

Second where are you setting the currentUserId variable?






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
An example:
I checked the 'code' via alert and saw that it was 'RRH'.
The 'currentUserId' was '78'.
My question is, how do you get 'code'(RRH) to equal 'currentUserID'(78) in javascript?
Code = RRH
RRH = 78
currentUserId = 78

Does that help?
 
Forgive me if I'm misunderstanding but what you are asking doesn't quite make sense, but perhaps what you want is instead of having a list if variables, to have an array. which you can then reference and assign to and compare from.

Code:
 var [red]code[/red] = salesman.innerHTML;
   var codes=new array();
   codes['RRH'] = 78;
   codes['DRH'] = 78;
   codes['BJS'] = 78;
   codes['SLA'] = 91;
   codes['MDT'] = 84;
   codes['CBC'] = 81;
   codes['CWS'] = 85;
   codes['TAB'] = 90;
   codes['MWM'] = 88;

if(codes[[red]code[/red]]==78){
...
}

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top