|
|
||||||
|
#1
|
|
|
|
|
I read data (e.g. äöüÄÖÜçéàè"') from my MySQL database which I'd like to
show in an input box. <?php $mysql_data = "äöüÄÖÜçéàè\"'"; $html_data = addslashes(htmlentities($mysql_data, ENT_QUOTES)); echo "<script type = 'text/javascript'>"; echo "function set_old_data() {"; echo "my_form.input1.value = var_old_data;"; echo "}"; echo "var_old_data = '" . $html_data . "';"; echo "</script>"; echo "<body>"; echo "<form name = 'my_form' action = '' method = 'post' accept-charset = 'iso-8859-1'>"; echo "<input type = 'text' name = 'input1' value = '" . $html_data . "'>"; echo "<input type = 'button' value = 'Old Data' onClick = 'set_old_data()'>"; echo "</form>"; echo "</body>"; ?> The command echo "<input type = 'text' name = 'input1' value = '" . $html_data . "'>"; shows my data äöüÄÖÜçéàè"' in the input box perfect. But if I click on the button 'Old Data' the Java script function 'set_old_data' shows in the input box äöüÄÖÜç&eacut e;àè"' instead of äöüÄÖÜçéàè"' Therefore I need a Java script function with translates äöüÄÖÜç&eacut e;àè"' to äöüÄÖÜçéàè"' In PHP I could do that with the function html_entity_decode() But how can I do it with a Java script? Stefan PS: html_entity_decode() is the opposite of htmlentities(). It converts all HTML entities to their applicable characters from string. |
|
|
|
#2
|
|
|
|
|
Stefan Mueller wrote:
[..] > In PHP I could do that with the function > html_entity_decode() > > But how can I do it with a Java script? > Stefan > > PS: html_entity_decode() is the opposite of htmlentities(). It converts all > HTML entities to their applicable characters from string. > Uh, maybe ask in a Javascript newsgroup? |
|
#3
|
|
|
|
|
Stefan Mueller wrote:
> Therefore I need a Java script function with translates > äöüÄÖÜç&eacut e;àè"' > to > äöüÄÖÜçéàè"' > > In PHP I could do that with the function > html_entity_decode() > > But how can I do it with a Java script? > Stefan > > PS: html_entity_decode() is the opposite of htmlentities(). It converts all > HTML entities to their applicable characters from string. This relies on IE extensions but you can it's possible to make it standard compatible. function html_entity_decode(s) { var span = document.createElement('SPAN'); span.innerHTML = s; return span.innerText; } |
|
#4
|
|
|
|
|
On a second thought, it's probably easier if you just dump the text
into a hidden field. |
|
#5
|
|
|
|
|
> function html_entity_decode(s) {
> var span = document.createElement('SPAN'); > span.innerHTML = s; > return span.innerText; > } Yea, this is exactly what I'm looking for. But like you mentioned it only works for IE and not for Mozilla, Opera, Safari, ... Stefan |
|
#6
|
|
|
|
|
Stefan Mueller wrote:
> > function html_entity_decode(s) { > > var span = document.createElement('SPAN'); > > span.innerHTML = s; > > return span.innerText; > > } > > Yea, this is exactly what I'm looking for. But like you mentioned it only > works for IE and not for Mozilla, Opera, Safari, ... > > Stefan Most browsers support innerHTML, even though it's non-standard, because it's so convinent. innerText is supported only by IE as far as I know. In the other browsers, you can get the plain text from span.firstChild.nodeValue. As I said in the follow-up, it's easier to store the original value in a hidden field parallel to the input field. Or better yet, use a onload handler to capture the initial values of every fields. Something like: function saveOriginalValues() { var inputs = document.getElementsByTagName('INPUT'); for(var i = 0; i < inputs.length; i++) { var input = inputs[i]; if(input.type == 'text') { originalValues[input.name] = input.value; } } } That gives you something that you can reuse across multiple forms. |
|
#7
|
|
|
|
|
> As I said in the follow-up, it's easier to store the original value in
> a hidden field parallel to the input field. Or better yet, use a onload > handler to capture the initial values of every fields. Something like: First of all thanks a lot for your solutions. Yea, I've also thought about your solution (hidden fields). However, I've a table with hundreds of fields. Today, to sort this table takes already some time. But if I add for each field a hidden field the sorting will take to much time. Therefore I try to find a solution to get the real characters (ä, ö, ü, ...) from the HTML characters (äöü, ...). In the worst case I've to write my own function (search for 'ä' and replace it with 'ä', then seach for 'ö' and replace it with 'ö', ...) Stefan |
|
|
| Similar Threads | |
| Convert special characters from HTML to utf-8 or iso-8859-1 Dear all, is there a gem available that will transform things like "" into a long dash, "'" into an apostrophe and so on ? I think someone posted about this about a week... |
|
| Special characters using html &..; Whenever I write norwegian characters like æ, ø and å, FrontPage no longer translates them into html-codes æ ø and å. In fact, if I code it like this directly into the html... |
|
| How to convert HTML entities to their applicable characters with a java script Because the characters ', ", ... make troubles in my input boxes I use the following PHP command while generating the page htmlentities($my_var, ENT_QUOTES); However, if I... |
|
| Special characters in java, oracle and html Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into... |
|
| Special characters in java, oracle and html Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into... |
|
|
All times are GMT. The time now is 09:50 AM. | Privacy Policy
|