[colug-php] PHP/Javascript empty text box issues
Rob Haag
rhaag71 at gmail.com
Wed Sep 30 05:57:52 EDT 2009
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
More information about the colug-php
mailing list