1 Replies - 270 Views - Last Post: 08 December 2011 - 11:57 PM

#1 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,822
  • Joined: 30-April 10

Using || (or) in an if statement correctly

Posted 08 December 2011 - 11:46 PM

I am trying to test the id of three input boxes so that I can capitalize the first letter.

if ((this.id == "fname" || this.id == "lname") || this.id == "mi"){
		var str = this.value.charAt(0).toUpperCase() + this.value.slice(1);
		this.value = str.toString();
	}



The fname and lname work fine but mi does nothing and I get no error is this because of the if statement or the fact that the mi only has one character?

This post has been edited by Dormilich: 09 December 2011 - 02:39 AM
Reason for edit:: fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Using || (or) in an if statement correctly

#2 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,822
  • Joined: 30-April 10

Re: Using || (or) in an if statement correctly

Posted 08 December 2011 - 11:57 PM

Sorry it was a syntax error else ware in the function. Fixed.

But, Just out of curiosity what is the best way to do this if you had more than three id's to check?
How many or statements can you use in an if statement or is there a better solution?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1