SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot boballoo's Avatar
    Join Date
    Dec 2001
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Apostrophe in a "value field" inside an "Input tag"

    In the folowing Input tag I am trying to get the apostrophe in "Friends" to appear and it almost works the way it is but when I first load the page the "\" (backslash) also shows up. If I click in the field (onfocus) the words "Friend\'s Email" disappear as they are supposed to. Then when I click somewhere else
    (onblur) it comes back like this "Friend's Email" which is the way I want it to appear when the page first loads. Is this a browser problem or something else I am missing?

    <input type="text" name="who_to" size="12" value="Friend\'s Email" maxlength="100" onFocus="if(this.value='Friend\'s Email') {this.value='';}" onBlur="if (this.value=='') {this.value='Friend\'s Email';}">


    Bob
    EditFast
    Any Document --> Any Time!
    Web Site Copy Editing & Proofreading


  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type="text" name="who_to" size="12" value="Friend& #39;s Email" ...

    & #39; is HTML
    \ ' is a string in javascript

    End of mystery

    No space between & and #!
    This is just to make the code visible on this page
    Last edited by jofa; Jun 16, 2002 at 19:04.

  3. #3
    SitePoint Zealot boballoo's Avatar
    Join Date
    Dec 2001
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha! Of course! That means it has to be different in both places. That is, "& #39;" in the HTML part of the Input tag and then "\" in the javascript part of the tag. This is what stumped me because I assumed they had to be the same. (They are the same actually, just different.

    <input type="text" name="who_name" size="12" value="Friend&#39;s Name" maxlength="100" onFocus="if(this.value='Friend\'s Name') {this.value='';}" onBlur="if (this.value=='') {this.value='Friend\'s Name';}">

    Thanks!

    Bob
    EditFast
    Any Document --> Any Time!
    Web Site Copy Editing & Proofreading



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
  •