Need help with isEmpty()

Discussion in 'JavaScript' started by hindlist, Dec 29, 2010.

  1. #1
    I am pretty much new to java script programming. I would like to get help with the following code

    <html>
    <head>
    <script>

    function str(txt){
    document.write(txt +'<br>');
    }

    function isEmpty(right){
    if(isEmpty=='0' ||isEmpty==' '){
    return false;}
    else{
    return true;}
    }
    </script>
    </head>
    <body></body> </html>

    Explanation of code: Above as isEmpty has been assigned a value(right), so if isEmpty is false then it should return as false, but the problem is that it is not showing any thing and in error console(in Mozilla) too its not showing any problem. It would be much appreciated if some body can look into it and offer a solution.,
    thank you all in advance.
     
    hindlist, Dec 29, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    function isEmpty(right) {
    	if ((right == '0')||(right == ' ')) return false;
    	else return true;
    }
    
    Code (markup):
    But that will still do nothing because isEmpty is not being called anywhere. I guess you want to test the text value with it, like this:
    
    <html>
    <head>
    <script>
    function str(txt) {
    	if (isEmpty(txt) == true) document.write(txt +'<br>');
    }
    
    function isEmpty(right) {
    	if ((right == '0')||(right == ' ')) return false;
    	else return true;
    }
    
    function doStuff() {
    	str("Hello");
    	str(" ");
    	str("World");
    }
    </script>
    </head>
    <body onload="doStuff();">
    </body> 
    </html>
    
    Code (markup):
     
    Cash Nebula, Dec 30, 2010 IP
  3. hindlist

    hindlist Member

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    This is what i am looking for. Thank you
     
    hindlist, Dec 31, 2010 IP