SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML tags in button value

    Is it possible to have HTML in a button value to show as processed HTML? Like this the raw HTML tags are displayed on the button instead of 'two cubed'.

    Code:
    $value = "2<sup>3</sup>";
    <input type = "button" name = "answerBTN" value="$value">
    Many thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by fvgb View Post
    Is it possible to have HTML in a button value to show as processed HTML? Like this the raw HTML tags are displayed on the button instead of 'two cubed'.

    Code:
    $value = "2<sup>3</sup>";
    <input type = "button" name = "answerBTN" value="$value">
    Many thanks
    Use <button name="answerRTN">$value</button> instead.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, but that gives me the same result (perhaps it has something to do with me using prepared statements.) Besides I would rather keep the 'input' buttons since the whole site is adapted to them.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The button tag is for applying HTML styling to the button content - that's the only reason why it exists - because using input type="button" only allows plain text.

    You also need to make sure that the value you are trying to use is not being processed through htmlspecialchars or htmlentities as that will convert the HTML tags in your content to text.

    Using prepared statements should have no effect whatever.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was converting the values to text. I removed that and have now also changed all buttons to the button tag. It works just fine.

    Many thanks for your help!


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
  •