Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7565559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:11:10+00:00 2026-05-30T14:11:10+00:00

I have a form built with jquery. I just want to have an empty

  • 0

I have a form built with jquery. I just want to have an empty form with onfocus set so when a user types something the text disappears.

var $myinput2 = js("<input id='CameraName' name='camera_name' size='24' maxlength='36' value='Enter label for camera' onfocus='if(this.value=='Enter label for camera') this.value='';'/>");

I get a syntax error pointing at the “if(this.value==”

I can’t seem to get the quoting right so this will work. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:11:12+00:00Added an answer on May 30, 2026 at 2:11 pm

    You just have to be careful about escaping quotation marks within a string literal if they’re the same type as the whole string literal is enclosed by.

    You’re using single-quotes for your html attributes, so within the inline onfocus handler your JS should use double-quotes but because the whole string is in double-quotes you have to escape those double-quotes:

    var $myinput2 = js("<input id='CameraName' name='camera_name' size='24' maxlength='36' value='Enter label for camera' onfocus='if(this.value==\"Enter label for camera\") this.value=\"\";'/>");
    

    That is, within your string literal the inline onfocus will look like this:

    "... onfocus='if(this.value==\"Enter label for camera\") this.value=\"\";' ..."
    

    Such that the actual value is:

     onfocus='if(this.value=="Enter label for camera") this.value="";'
    

    Note that you wouldn’t have this problem if you didn’t use an inline event handler and instead did something like:

    var $myinput2 = js("<input id='CameraName' name='camera_name' size='24' maxlength='36' value='Enter label for camera' />");
    $myinput2.focus(function() {
      if(this.value=="Enter label for camera")
         this.value="";
    });
    

    (I’m assuming that js is your alias for jQuery.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have the action of a HTML form built when the user
I have successfully built a login form using ajax and want to add a
I have a form that jQuery tracks the onChage .change() event so when something
I have just built a custom autocomplete component using jquery. My problem is that
I have a PHP/jQuery/AJAX/MySQL app built for managing databases. I want to implement the
I have a Windows Form application built on a data model and a Windows
I have a form I've built in PHP and storing the form field values
I have an MVC view with a form built with the Ajax.BeginForm() helper method,
I have a form I am submitting via AJAX (using prototype and the built-in
I have the following situation: I built an Access form with a subform (which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.