I have short form in HTML. This is chat window and I would like to pass there not only user message but also some hidden data to file "post.php" which is in upper folder.
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="63" />
<input name="company" type="hidden" id="company" value="<?php echo $kawalki_adres[2]; ?>"/>
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
Here is AJAX
<script type="text/javascript">
//If user submits the form
$("#submitmsg").click(function(){
var clientmsg = $("#usermsg").val();
var company = $("#company").val();
$.post("../post.php", {text: clientmsg, company});
$("#usermsg").attr("value", "");
$("#company").attr("value", "");
return false;
});
I'm taking user's message correctly in "post.php" but not sure how to receive "company" variable.
Use like this
Make sure you are setting the value of company by PHP
$("#submitmsg").click(function(e){
e.preventDefault(); //prevents form submit, otherwise pages gets reloaded
var clientmsg = $("#usermsg").val();
var company = $("#company").val();
$.post("../post.php", {text: clientmsg, company: company});
$("#usermsg").attr("value", "");
$("#company").attr("value", "");
return false;
});