Jump to content

Textarea not formatting text in IE only


Zergman

Recommended Posts

Using ajax to perform a simple query using a dropdown that retrieves a template from the mysql table and loads that template into a textarea.

 

When it loads into the textarea, the formatting is kept in FF perfectly.  In all versions of IE, it loses the formatting.

 

Example

Firefox

1
2
3

 

Internet Explorer

1 2 3

 

The textarea

<textarea name="coach_details" id="txtHint" class="textareastyle" style="width:99%;" rows="20" ><?php echo set_value('coach_details');?></textarea>

 

Javascript

function showUser(str)
{
if (str=="")
  {
  document.getElementById('txtHint').innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('txtHint').innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_template.php?q="+str,true);
xmlhttp.send();
}

 

get_template.php

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
  {
  	die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

$sql="
SELECT template 
FROM coaching 
WHERE menu_id = '$q'
";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);

$template = $row['template'];

echo $template;

mysql_close($con);
?>

 

I'm so stuck.  Sadly though our company still uses IE alot so has to work for both.

 

Suggestions?

Link to comment
https://forums.phpfreaks.com/topic/233447-textarea-not-formatting-text-in-ie-only/
Share on other sites

Here's is one of the templates

 

Firefox

TT#: Please be sure to check for open/pending tickets before beginning a new Trouble Ticket. For more information please refer to xxxx regarding Second or Subsequent Call - How to add Activities to an Existing TT: http://long_url 
TT#: 

Please be sure to check for open/pending tickets before beginning a new Trouble Ticket. 

For more information please refer to the xxxx regarding Second or Subsequent Call - How to add Activities to an Existing TT:

http://long_url 

 

IE

TT#: Please be sure to check for open/pending tickets before beginning a new Trouble Ticket. For more information please refer to xxxx regarding Second or Subsequent Call - How to add Activities to an Existing TT: http://long_url 

 

Should also mention i've tried setting the mysql field type to blob to text, neither seemed to make a difference.

Just had a thought.. it may be because the html code around or before it is invalid. Have you run it through the W3C validator?

 

I have and it checked fine.

 

I built a small test app that does the same thing and it worked fine. 

 

Couple things that are different in the above is that im using fancybox to show the div in a popup.  Also using Codeigniter.

 

hmmmm

Did more looking and think this is how it should look, but yet, not working.

 

function showUser(str)
{
var xmlhttp;
if (str=="")
  {
  document.getElementById('txtHint').innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('txtHint').innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","http://mysite.com/site/assets/includes/get_template.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(str);
}

 

Changed the get_template to

$q = $_POST["str"];

 

Any ideas?

Looks like it's an issue with the way the line break is being stored/retrieved from the database.  I am willing to bet the database is either storing or feeding the line breakes in *nix format, and IE, being IE, gets all upset because it's not windows format.

 

Just a thought, but check on the line break code and see what it's using.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.