Jump to content

[object HTMLInputElement]


otester

Recommended Posts

I am currently trying to implement Ajax into a new chat function, however in the database under messages it keeps showing up as: [object HTMLInputElement] but the date (CURRENT_TIMESTAMP) works fine.

 

Why does it do this?

 

Here is the main code for the page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript" src="jquery-1.4.js"></script>

<script type="text/javascript">

$(document).ready(function(){  
    $("form#submit").submit(function() {  
    // we want to store the values from the form input box, then send via ajax below  
    var fname     = $('#Messages').attr('value'); 
        $.ajax({  
            type: "POST",  
            url: "ajax2.php",  
            data: "Messages="+ Messages,  
            success: function(){  
                $('form#submit').hide(function(){$('div.success').fadeIn();});
  
            }  
        });  
    return false;  
    });  
});  

</script>
</head>

<body>

<div class="container">  
<form id="submit" method="post">  
        <fieldset>  
            <legend>Enter Information</legend>  
            
            <label for="Messages">Message:</label>  
<input id="Messages" class="text" name="Messages" size="20" type="text">
  
            <button class="button positive">Submit comment!</button>  
        </fieldset>  
    </form>  
<div class="success" style="display:none;">Comment has been added.</div>  
</div>

</body>
</html>

 

Ajax2.php file:

 

<?php
$con = mysql_connect("x","x","x");
if (!$con)
  	{
  	die('Could not connect: ' . mysql_error());
  	}

mysql_select_db("x", $con);

// CLIENT INFORMATION
$Messages = htmlspecialchars(trim($_POST['Messages']));

    $addClient  = "INSERT INTO Comments (Messages,Date) VALUES ('$Messages', CURRENT_TIMESTAMP)";
    mysql_query($addClient) or die(mysql_error());
?>

 

Any help would be greatly appreciated,

 

Thanks,

 

otester

Link to comment
https://forums.phpfreaks.com/topic/209711-object-htmlinputelement/
Share on other sites

replace your jquery with this:

$(document).ready(function(){  
    $("form#submit").submit(function() {  
    // we want to store the values from the form input box, then send via ajax below  
    var mssg = $('#Messages').val(); 
        $.ajax({  
            type: "POST",  
            url: "ajax2.php",  
            data: "Messages="+ mssg,  
            success: function(){  
                $('form#submit').hide(function(){$('div.success').fadeIn();});
  
            }  
        });  
    return false;  
    });  
});  

replace your jquery with this:

$(document).ready(function(){  
    $("form#submit").submit(function() {  
    // we want to store the values from the form input box, then send via ajax below  
    var mssg = $('#Messages').val(); 
        $.ajax({  
            type: "POST",  
            url: "ajax2.php",  
            data: "Messages="+ mssg,  
            success: function(){  
                $('form#submit').hide(function(){$('div.success').fadeIn();});
  
            }  
        });  
    return false;  
    });  
});  

 

I see that I forgot to replace fname with Messages, thanks for your help!

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.