javascript+form+search problem...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
japaja
Forum Newbie
Posts: 6
Joined: Sun Apr 06, 2003 8:58 am

javascript+form+search problem...

Post by japaja »

In "form" part I added...

Code: Select all

<form name="form" action="search.php" method="get">
<input type="text" name="q" />
<input type="text" name="q" value="search..." onfocus="value=''" size="16" height="20" />
</form>
<?php

  // Get the search variable from URL

  $var = @$_GET&#1111;'q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// check for an empty string and display a message.

if (($q == "") && ($q == "Search..."))
  &#123;
  echo "<p>Please enter a search...</p>";
  exit;
  &#125;

// check for a search parameter
if (!isset($var))
  &#123;
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  &#125;

And "search..." is always in the search box..when you want to search something you just click on it and it becomes blank...

But there is the problem when you write nothing in search box form and then push the search button...you will get the search result with "search..." or any other word you write it down in that form part...



so..huh...my question is...
how to "block" searching and to get echo "<p>Please enter a search...</p>";
no matter is there nothing in search form box or where are my value="search..." onfocus="value=''" is in it..

p.s.
onfocus="value=''"
is
onfocus="value=' ' "
japaja
Forum Newbie
Posts: 6
Joined: Sun Apr 06, 2003 8:58 am

Post by japaja »

Finally I founded the solution for my problem ..Thank yOU TexasMan

Oh what a DUMMY I AM!

The logical OR || not the logical AND &&.


Code: Select all

if ( $trimmed  == "" || $trimmed  == "search..." ) 
&#123; 
echo "<p>Please enter a search...</p>"; 
&#125;
Post Reply