simple Ajax program not working

I am writing a simple AJAXprgram but that is not working.
Can you please let me know where I am missing:

<script type="text/javascript">
 function jqsubmit(){
             jQuery.ajax({
                   type:"POST",
                   url:"yahoocontact.php",
                   data:"text="+ value,
                   timeout:3000,
                   success: function()
                   { $("#results").html("<p>hai</p>")}                   
             })}
</script>


I have in my form:
<tr>
                    <td colspan="2" align="center"><input type="submit" onclick="jqsubmit()" name="Submit" value="Submit" /></td>
                    </tr>
                </table>  
                      
                </form>

---
Created a div after Form:
    <div id="results">
    <p> this is the default text</p>
    </div>
   
--
Yahoocontact.php is :


<?php


      $name1 = $_POST['name'];
      $email1= $_POST['email'];
      $emailError = "";
      $validated = true;

      
if($validated)
{
snip
}
else
{
snip
}


$response= "Thanks Sir";
echo $response;



                   else\
{
?>
</span></p>
<p>&nbsp;</p>
<p>
<?PHP
}
?>

vkchaitu82Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sudaraka WijesingheWeb Application ProgrammerCommented:
In your jqsubmot function, the value variable is not defined. (Also couple semicolons are missing, but nowadays browsers excuse that).

function jqsubmit(){
     var value='some value'; // <-- Initializing the variable "value" used in post data
     
             jQuery.ajax({
                   type:"POST",
                   url:"yahoocontact.php",
                   data:"text="+ value,
                   timeout:3000,
                   success: function()
                   { $("#results").html("<p>hai</p>");}                   
             });}

Open in new window

vkchaitu82Author Commented:
Thanks sudhakara.
I did try with ur suggestion of initializating the variable. I still dont see the out put
vkchaitu82Author Commented:
is this declaration correct:
<tr>
                    <td colspan="2" align="center"><input type="submit" onclick="jqsubmit()" name="Submit" value="Submit" /></td>
                    </tr>
                </table>  
                     
                </form>
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

mydropzCommented:
i don't know how your form looks like but you can send al the form data with
function jqsubmit(){
     
     
             jQuery.ajax({
                   type:"POST",
                   url:"yahoocontact.php",
                   data:$('#form_id').serialize(), //use serialize to send the form values
                   timeout:3000,
                   success: function()
                   { $("#results").html("<p>hai</p>");}                   
             });}

Open in new window

instead to put the function in the onclick of the form you can bind it to the form submit event
$('#form_id').submit(function(){
jqsubmit();
return false;
});

Open in new window

vkchaitu82Author Commented:
Thanks mydropz.
what does serialize do? I tried with that but no change.?

script:
             jQuery.ajax({
                   type:"POST",
                   url:"yahoocontact.php",
                   data:$('form123').serialize(),
                   timeout:3000,
                   success: function(success)
                   { $("#results").html("<p>hai"+success+"</p>")}                   
             })}
here is my form:

 <form id="form123" method="post" action="post" >

            <table width="53%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="16%">Name   </td>
                    <td width="84%"><input name="name" type="text" id="name" /></td>
                </tr>

               <tr>
                <td>Comments</td>
                <td><label for="Comments"></label>
                <textarea name="comments" id="comments" cols="45" rows="5"></textarea></td>
             </tr>
                  <tr>
                    <td colspan="2" align="center"><input type="button" onclick="jqsubmit()" value="Submit1" /></td>
                    </tr>
                </table>  
                      
                </form>

----
mydropzCommented:
you forget the # tag
$('#form123').serialize() // don't forget #

Open in new window


more on jquery serialize
vkchaitu82Author Commented:
I tried with this:

             jQuery.ajax({
                   type:"POST",
                   url:"yahoocontact.php",
                   data:$("#form123").serialize(),
                   timeout:3000,
                   success: function(success)
                   { $("#results").html("<p>hai"+success+"</p>")}                   
             })}

I can see in Post that the variables are been send (using firebug) . but there is no response from script.

my script is :
<?php


      $name1 = $_POST['name'];
      $email1= $_POST['email'];
      $emailError = "";
      $validated = true;

     
if($validated)
{
snip
}
else
{
snip
}


$response= "Thanks Sir";
echo $response;



                   else\
{
?>
</span></p>
<p>&nbsp;</p>
<p>
<?PHP
}
?>

is there anything I am missing there
vkchaitu82Author Commented:
Thanks mydropz:.
I found after posting that I missed the tag :-)
mydropzCommented:
what is the purpose of this part of your script
                   else\
{
?>
</span></p>
<p>&nbsp;</p>
<p>
<?PHP
}
?>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vkchaitu82Author Commented:
Thanks mydropz. that was the issue:) I forgot to remove, initially I had them to check the post.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.