0

on my web page i have text area like this enter image description here

and i suppose to get data in textarea when i alternate the value of select box( or onChange event), so i used ajax function

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script>                          
                function myCall() {
                    var request = $.ajax({
                        url: "ajax.php",
                        type: "GET",            
                        dataType: "html"
                    });

                    request.done(function(msg) {
                        $("#mybox").html(msg);          
                    });

                    request.fail(function(jqXHR, textStatus) {
                        alert( "Request failed: " + textStatus );
                    });
                }

        </script>

and this is my select box code,

<select name="txtname" id="txtname" onChange="myCall()" >
    <option value="0">Select Age:</option>
    <option value="100083">100083</option>
    <option value="22-26">22-26</option>
    <option value="26-30">26-30</option>
    <option value="30-34">30-34</option>

    </select>

actualy i want to fetch record on the basis of select box value, this function working fine for static value but i am puzzled how to get data from data base.. and my ajax page coding is here..

<?php



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

mysql_select_db("hmc", $con);


$sql="SELECT * FROM news WHERE name = '22-26'";

$result = mysql_query($sql);
?>


                       <?php
  while($row=mysql_fetch_array($result))
{
?>
        <tr>
<td>
<?php echo $row['news1'];?></h3></td>

</tr><br /><hr /><br />

<?php
}
?>




</div>

any idea will be appreciated...

1
  • i want to fetch record in textarea by onchange Commented Apr 18, 2013 at 12:03

1 Answer 1

1

Your ajax call is not proper, you need to pass your select box value to the php side, like this

$.ajax({
                    url: "ajax.php",
                    type: "GET",            
                    dataType: "html",
                    data:"value="+$("#txtname").val();
                });

then use this value on php side using $_GET['value']

Sign up to request clarification or add additional context in comments.

2 Comments

i paste all relevent data regarding ajax call...can you tell me how to get "value" on ajax.php page, i tried like this $q=$_GET['value'];
but on my original page its showing request failed: error...??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.