SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Europe :-)
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript+form+search problem...

    In "form" part I added...
    Code:
    <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['q'] ;
      $trimmed = trim($var); //trim whitespace from the stored variable
    
    // check for an empty string and display a message.
    
    if (($q == "") && ($q == "Search..."))
      {
      echo "<p>Please enter a search...</p>";
      exit;
      }
    
    // check for a search parameter
    if (!isset($var))
      {
      echo "<p>We dont seem to have a search parameter!</p>";
      exit;
      }

    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=' ' "

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a PHP question, isn't it?

    Anyhow, you need
    Code:
    if ( $q == "" || $q == "search..." )
    {
    echo "<p>Please enter a search...</p>";
    }
    The logical OR || not the logical AND &&. Also, equality checks are case-sensitive, so I put in a lower-case s since that is what your form uses.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Europe :-)
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah TexasMan thats I wanted..Thank You...Thank you very much :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •