views:

14

answers:

0

I am having a weird time with an Opera Unite web app I'm getting my feet wet with. I'm using the getItem() function to return data that's posted. Now that's supposed to return null if there's no such value, which works, my first conditional works when there's no POST. It even works when I post a value. What's messing up is when I post a blank field. message[0] returns with a length of 0 (as the second alert will show), but comparing message[0].length to 0, "0", or <1 or message to "", false, null never registers as true. It's like it knows the value is empty, but it's using some other way that 0 to express that. Here's the code I'm using:

function showHelloWorld(e) {

    var response = e.connection.response;
    var request = e.connection.request;
    var message = request.getItem('message', 'POST');
    var p = opera.io.webserver.currentServicePath + "hello";

    if (message == null) {
        message = new Array();
        message[0] = "Hello, world! 1";
    }

    if (message[0] == false || message[0] == "" || message[0] == null) {
        message[0] = "Hello, world! 2";
    }

    response.write('<!DOCTYPE html>'
                   + '<html><head><title>Hello</title></head>'
                   + '<script type="text/javascript">'
                   + 'alert(' + message.length + ');' 
                   + 'alert(' + message[0].length + ');'
                   + '</script>'
                   + '<body><form method="post" action="' + p + '">'
                   + '<p>' + message + ' - ' + message[0] + '</p><hr>'
                   + '<input type="text" name="message" value=""><input type="submit">'
                   + '</form></body></html>');

     response.close();
}

Has anyone else run into this problem? Any help would be appreciated. I'm at my wits end. Thanks!