Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Search box - need to only show search results, not all results when enter pressed

Posted on 2005-05-01
4
Medium Priority
?
229 Views
Last Modified: 2006-11-18
I hope I am posting in the best area for this.

I have a search box in a form which works well.  I type in the search text and press enter and it works great and returns the results correctly.  However if I just press enter and when no text is entered into the search box, it returns everything in the table.  I would rather if just ENTER return no results if no search criteria was given.i

I would be happy with the most  simple solution to solve this (whether it be php, javascript, etc.)

Thank you


0
Comment
Question by:debbieau1
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13906181
With JavaScript:

<script>
function validate(theForm){
 if((theForm.text_fld.value).replace(/^\s*|\s*$/g,"") == ""){
  alert("no information entered");
  theForm.text_fld.focus();
  return false;
 }
 return true;
}
</script>
<form onsubmit="return validate(this)">
<input type="text" name="text_fld" value="" />
<input type="submit" />
</form>

With PHP:

if(!isset($_POST["text_fld"]) || trim($_POST["text_fld"]) == "") {
 // Dont execute the query, return error message.
}
0
 
LVL 1

Author Comment

by:debbieau1
ID: 13906773
Thanks for providing two explanations.  I am sorry to trouble but I cannot get it to work.

I would really appreciate if you could help me some more.

Here is what I have.  I have a style and the appearance changes when it is clicked.
---------------------------------------------

  <td width="252"><form action="courseglossary.php" method="get" name="form1" target="_self" class="style3" id="form1">

  <input name="glossarybox" type="text" id="glossarybox" size="25"onfocus="this.className='ClickedBox'" onBlur="this.className=''">
    </form></td>
0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 2000 total points
ID: 13906780
<script>
function validate(theForm){
 if((theForm.glossarybox.value).replace(/^\s*|\s*$/g,"") == ""){
  alert("no information entered");
  theForm.glossarybox.focus();
  return false;
 }
 return true;
}
</script>

...
...

<td width="252">
 <form action="courseglossary.php" method="get" name="form1" target="_self" class="style3" id="form1" onsubmit="return validate(this)">
  <input name="glossarybox" type="text" id="glossarybox" size="25" onfocus="this.className='ClickedBox'" onBlur="this.className=''">
  </form>
</td>
0
 
LVL 1

Author Comment

by:debbieau1
ID: 13906804
Thanks heaps!!  Works great!

Debbie
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question