SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    0 Post(s)
    0 Thread(s)

    Using an apostrophe in an input field

    Hi there,

    I am trying to use an apotrophe in an input fields with this code, but it isn't working. Is there a way I can use apostrophes in the below. I am referring to the values of "your friend's name".

    PHP Code:
    onblur="if (this.value == '') {this.value = 'your friend's name';}"
    onfocus="if(this.value == 'your friend's name') {this.value = '';}" value="your friend's name" 

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Melbourne, AU
    17 Post(s)
    1 Thread(s)
    Instead of trying to match the value against the exact value you need match against what you can do is use a property like is kind of how to find if your still newish to JavaScript which is defaultValue, basically this property stores the initial value of the input field allowing you to match it again something else.

    See the below:
    HTML Code:
    <input onblur="if (!this.value.length) this.value = this.defaultValue;" onfocus="if (this.value === this.defaultValue) this.value = '';" value="your friend's name" />
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


Posting Permissions

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