www.webdeveloper.com
Results 1 to 2 of 2

Thread: catching boolean from vars to if statements

  1. #1
    Join Date
    Mar 2007
    Posts
    6

    catching boolean from vars to if statements

    Hi I just started to learn javascript and I am trying to write a function.
    I start with a confirm method and capture a true or false value in a variable.
    If the confirm returns true then the if executes an alert, if the confirm returns false then the else also returns an alert.

    what I am unsure of is how to apply the confirm true or false value to the if and else statment after I capture it in a variable.

    example.

    var con="";

    con = confirm("true or false");

    if(HOW DO YOU WRITE A RETURN TRUE VALUE FROM THE CONFIM VAR){
    alert("value retured true")
    }

    else{
    alert("value retured false")
    }

    thanks for any help.

  2. #2
    Join Date
    Oct 2006
    Posts
    120
    Code:
    <script type="text/javascript">
    	function CheckConfirm()
    	{
    		var confirmBox = confirm('true or false');
    		if (confirmBox)
    			alert('TRUE');
    		else 
    			alert('FALSE');
    	}
    	CheckConfirm();
    </script>
    Code:
    <script type="text/javascript">
    	function CheckConfirm()
    	{
    		var confirmBox = confirm('true or false');
    		if (!confirmBox)
    			alert('FALSE');
    		else 
    			alert('TRUE');
    	}
    	CheckConfirm();
    </script>
    Code:
    <script type="text/javascript">
    	function CheckConfirm()
    	{
    		var confirmBox = confirm('true or false');
    		alert((confirmBox) ? 'TRUE' : 'FALSE');
    	}
    	CheckConfirm();
    </script>
    Code:
    <script type="text/javascript">
    	function CheckConfirm()
    	{
    		var confirmBox = confirm('true or false');
    		if (!confirmBox)
    		{
    			alert('FALSE');
    			return;
    		}
    		alert('TRUE');
    	}
    	CheckConfirm();
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles