SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using quotes in value for forms

    This should be a quick question but I couldn't find anything about it when I was searching.

    I was wondering if it was possible to have quotes within the value of a form field.

    eg.

    <input type="text" name="nameoffield" value="Something "nice" here">

    Right now if I just enter the above, then the value inside that text field is 'Something '. Anything after the " ceases to exist. Is there a way to make all the quotes appear inside the text field?

    In PHP we would use \" and in ASP we use "" but what about HTML?

  2. #2
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't quite work out why you'd want to do that, but the easiest solution would be to use single quotes outside the double quotes:

    value='Some "value" goes here'

    I've not tested this, but it seems like it should work.
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  3. #3
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would that work as follows:

    $variable="some \"values\" here"
    value='some value from <?=$variable?>'

    or would the value actually display
    some value from <?=$variable?>

    instead of
    some value from some "values" here

    ?? i guess I could just test and see...

  4. #4
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In HTML you need to escape the characters by replacing them with their HTML entity equivalents. Hi there, "this has quotes in" should become Hi there, &amp;quot;this has quotes in&amp;quot;

    I think single quotes are replaced by &amp;apos; but it's worth checking that to make sure.

    The PHP htmlspecialchars() function can take a string and encode it in this way for you. Very handy for outputting variables as the value of a form input element in a PHP script.

  5. #5
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beautiful!! That was it...

    Thanks for that Skunk!


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
  •