if condition in javascript?

Discussion in 'JavaScript' started by abpwebservices, Oct 13, 2011.

  1. #1
    Hello everybody!!

    I have a small issue:

    I have the following code:

    state0: {
    						html:'EXAMPLE TEXT<div class="field"><table width="100%"><tr><td>Name</td><td><input type="text" id="Name" name="name" value="" /></td></tr></table></div>',
    						buttons: { Cancel: false, Continue: true},
    						focus: 1,
    						submit:function(v,m,f){ 
    							if(v==0) 
    								$.prompt.close()
    							else if(v==1) { 
    								[COLOR="#FF0000"]if( name isn't empty  )[/COLOR]	execute -> $.prompt.goToState('state1');}//go forward
                                                                                                 if not make the input border red?
    							return false; 
    						}
    Code (markup):
    1.How should I write the red if, if I want to get to the next state (state1) only if name isn't empty? (I know how to write the condition in php, but here I don't know how to get the name value)
    2.How do I make the names input border red if the condition is not respected?

    Please help me with a code because I feel that I'm loosing my mind..

    Thanks a lot
     
    abpwebservices, Oct 13, 2011 IP
  2. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, use the getElementById method to retrieve the input, the value property of the input to get its value and the border style property to change its border settings:

    submit:function(v,m,f){ 
    	if (v==0) {
    		$.prompt.close();
    	}
    	else if(v==1) { 
    		var input = document.getElementById ("name");
    		if (input.value) {
    			input.style.border = "";
    			return false;
    		}
    		else {
    			input.style.border = "2px solid red";
    		}
    	}
    	return true;
    }
    
    Code (markup):
     
    gumape, Oct 14, 2011 IP
  3. abpwebservices

    abpwebservices Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks gumape!

    I will try it!
     
    abpwebservices, Oct 14, 2011 IP
  4. abpwebservices

    abpwebservices Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes it is working... thanks a lot
     
    abpwebservices, Oct 14, 2011 IP