tags:

views:

37

answers:

2

I want to show a predefined value in the text box which may contain special characters like ' i.e. single quote e.g. Amit's Birthday.... When I am displaying the string it shows only Amit and omitted the further string. I used htmlspecialchars() function as i am using php but its not happening result is still same. Some body please Help me with this

A: 

From the manual: http://php.net/htmlspecialchars

''' (single quote) becomes ''' only when ENT_QUOTES is set.

So either delimit your attribute values with double quotes, instead of single, or set ENT_QUOTES (as per Example 1 on the page linked above).

David Dorward
+1  A: 

from server side send data as html encoded with htmlspecialschars

<?php
   $new = htmlspecialchars("Amit's Birthday", ENT_QUOTES);
   echo $new; // Amit&#039;s Birthday;
?>

if your setting value attribute on server side then it will be encoded string with & # 0 3 9; inplace of single quote and same for if you are doing it on client side with ajax call for fetching data.

Put id, name or class attribute of your input field then write this code on document on load function or when you have input field filled with required data.

   // < input class="decodeIt" type="text" value="Amit&#039;s Birthday" />    

    var decodedValue = $(".decodeIt").val().replace("&#039;", "'");
    $(".decodeIt").val(decodedValue );
Ayaz Alavi