Welcome Guest, Not a member yet? Register   Sign In
AJAX search using dropdown troubles
#1

[eluser]CI_Newb[/eluser]
I'm at my wits end on this so I need help.

What i have is a auto populated dropdown. Right below that dropdown is a textarea.

User selects an option from the dropdown and it populates the textarea with data from their selection.

I can get it to work using straight ajax requests but the issue im having is that the textarea in Internet Explorer doesn't have the formatting where Firefox does.

Example of textarea in Firefox
Code:
1
2
3

Example of textarea in Internet Explorer
Code:
1 2 3

Now I read that a possible reason is that IE doesn't handle large text over GET requests and suggested I use POST but I can't figure out how to modify the code i already have for POST so i'm trying to do this using CI which would use POST.

Here's what I have so far.

script on the same page as form fields are on
Code:
function showUser(str)
{
if (str=="")
  {
  document.getElementById('txtHint')[removed]="";
  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')[removed]=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://mysite.com/site/assets/includes/get_template.php?q="+str,true);
xmlhttp.send();
}

get_template.php
Code:
<?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 db_table
WHERE menu_id = '$q'
";

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

$template = $row['template'];

print_r($template);

mysql_close($con);

?>

form fields
Code:
<?php
$js = 'id="coach_subject" onchange="showUser(this.value)"';
echo form_dropdown('coach_subject', $coaching_subject, set_value('coach_subject', '0'), $js);
?>

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

HELP!!!


Messages In This Thread
AJAX search using dropdown troubles - by El Forum - 04-13-2011, 08:10 PM
AJAX search using dropdown troubles - by El Forum - 04-13-2011, 10:09 PM
AJAX search using dropdown troubles - by El Forum - 04-13-2011, 10:37 PM
AJAX search using dropdown troubles - by El Forum - 04-13-2011, 11:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB