From herrold at owlriver.com  Tue Sep  1 18:08:37 2009
From: herrold at owlriver.com (R P Herrold)
Date: Tue, 1 Sep 2009 18:08:37 -0400 (EDT)
Subject: [colug-php] prime the new host
Message-ID: <alpine.LRH.2.00.0909011808220.26745@arj.bjyevire.pbz>


From rhaag71 at gmail.com  Wed Sep 30 05:57:52 2009
From: rhaag71 at gmail.com (Rob Haag)
Date: Wed, 30 Sep 2009 05:57:52 -0400 (EDT)
Subject: [colug-php] PHP/Javascript empty text box issues
In-Reply-To: <24575979.01254304547481.JavaMail.rob@albert3>
Message-ID: <24776106.21254304670087.JavaMail.rob@albert3>

Hi, I'm working on a search engine for a database, I found that if a search for whitespace (empty form) is made...it takes a long time (it does turn up results albeit useless), so I am trying to implement this as a check...
I have this in my document head (I found it on the web @ http://www.tizag.com/javascriptT/javascriptform.php:

<script type='text/javascript'>
function notEmpty(elem, helperMsg){
    if(elem.value.length == 0){
        alert(helperMsg);
        elem.SetValue("Bill Gates Sucks");
        elem.focus();
        return false;
    }
    return false;
}
</script>

I tried adding the 'SetValue' to at least try and throw in a default string (I was gonna change it before putting it up for my client :) )
I also did have the 'else' section as 'return true;' but I thought a hard return false may work...it don't (I also read something about the Geko browser engine not using the 'focus', and it does not refocus when an empty box is used either.


this is my form:
       <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">  
            <label for="search_text"> Search in Database</label><br />
            <input type="text" name="search_text" <?php if(isset($_POST['search_text'])) echo 'value="'.$_POST['search_text'].'"';  ?> id='req1'/>
            <input type="submit" 
                   onclick="notEmpty(document.getElementById('req1'), 'Please Enter a Value (Searching for Nothing takes a really long time.')" 
                   value="Search" class="btn2"/>
        </form>

if I submit an empty box, the popup with the alert works, but after clicking 'ok' it continues with the flow anyway...thus searching for 'nothing'...taking a long time making debugging quite frustrating :) Any help/suggestions would be much appreciated, thanks in advance...



-- 
Rob Haag


