What are these colons and question marks in javascript?

Discussion in 'HTML & Website Design' started by offthedome, Mar 24, 2008.

  1. #1
    In particular, what does this code mean?

    
    	document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
    
    HTML:

     
    offthedome, Mar 24, 2008 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    It says that if the value is "stop", change it to "start", otherwise (it says "start") make it "stop". It's what's called a tertiary statement.

    What "slideform" and its child/attribute/whatever, "slidebutton" mean can't be known without seeing the assignment statements.

    cheers,

    gary
     
    kk5st, Mar 24, 2008 IP
  3. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I always thought it was "if true"... the : I'd like to know... seems like "or".
     
    Stomme poes, Mar 24, 2008 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    Basically, it's an if else statement in shorthand.

    cheers,

    gary
     
    kk5st, Mar 27, 2008 IP