Results 1 to 5 of 5

Thread: Stumped!

  1. #1
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stumped!

    what's wrong with this code that it is returning an error?


    echo '<form action="/search.php" method="GET" style="margin-bottom:2px;margin-top:5px">';
    echo '<input type="text" onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue" name="search" style="width:95px" value="keyword search">';
    echo '<input type="hidden" name="startrow" value="0">';
    echo '<input type="submit" value="Go!">';

    have a feeling it's to do with this [onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue"] nested part of the code that empties the input box when clicked by the user?

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    break out of php mode when parsing

    PHP Code:
    <?php
    ...
    echo 
    ?>
    <form action="/search.php" method="get" style="margin-bottom:2px;margin-top:5px">
       <input type="text" onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue" name="search" style="width:95px" value="keyword search">
       <input type="hidden" name="startrow" value="0">
       <input type="submit" value="Go!">
    </form>
    <?php 
    // resume php code
    also
    onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue"
    see
    http://www.dynamicdrive.com/forums/s...54&postcount=3

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You have single quotes inside of single quotes. Break out of PHP parsing mode to output complex data like HTML:
    Code:
    ?>
    <form action="/search.php" method="get" style="margin-bottom: 2px; margin-top: 5px;">
      <input
        type="text"
        onfocus="this.value === this.defaultValue && (this.value = '');"
        onblur="this.value = this.value || this.defaultValue;"
        name="search"
        style="width: 95px;"
        value="keyword search"
      >
      <input type="hidden" name="startrow" value="0">
      <input type="submit" value="Go!">
    </form>
    <?php
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    And/or escape like this:
    'Something abc\'def something'
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's all very well for small strings, but in large or complex chunks of code it vastly detracts from readability and introduces another potential bug with every character that needs to be escaped.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •