I seen to be having a problem with jQuery not receiving the value of a form.
I have the form in a hidden div, user clicks 'send pm' the form appears.
<div class="interactContainers" id="private_message1">
<form action="javascript:sendPM();" name="pmForm" id="pmForm" method="post">
<font size="+1">Sending Private Message to <strong><em><?php echo "$username"; ?></em></strong></font><br /><br />
Subject:
<input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:90%;" />
Message:
<textarea name="pmTextArea" id="pmTextArea" rows="8" style="width:90%;"></textarea>
<input name="pm_sender_id" id="pm_sender_id" type="hidden" value="<?php echo $sessionid ?>" />
<input name="pm_sender_name" id="pm_sender_name" type="hidden" value="<?php echo $user ?>" />
<input name="pm_rec_id" id="pm_rec_id" type="hidden" value="<?php echo $profileid ?>" />
<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo $username ?>" />
<input name="pmWipit" id="pmWipit" type="hidden" value="<?php echo $thisRandNum ?>" />
<span id="PMStatus" style="color:#F00;"></span>
<br /><input name="pmSubmit" type="submit" value="Submit" />
<span id="pmFormProcessGif" style="display:none;"><img src="../_Images/loading.gif" width="28" height="10" alt="Loading" /></span></form>
</div>
i have a JQuery script that checks the info has been inputed but its keeps telling me the data is not being received.
I keep getting either a 'Please type a subject' or 'Please type a message' output
the JQuery
$('#pmForm').submit(function(){$('input[type=submit]', this).attr('disabled', 'disabled');});
function sendPM ( ) {
var pmSubject = $("#pmSubject");
var pmTextArea = $("#pmTextArea");
var sendername = $("#pm_sender_name");
var senderid = $("#pm_sender_id");
var recName = $("#pm_rec_name");
var recID = $("#pm_rec_id");
var pm_wipit = $("#pmWipit");
var url = "../_Scripts/private_msg_parse.php";
if (pmSubject.val() == "") {
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type a subject.').show().fadeOut(6000);
} else if (pmTextArea.val() == "") {
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type in your message.').show().fadeOut(6000);
} else {
$("#pmFormProcessGif").show();
$.post(url,{ subject: pmSubject.val(), message: pmTextArea.val(), senderName: sendername.val(), senderID: senderid.val(), rcpntName: recName.val(), rcpntID: recID.val(), thisWipit: pm_wipit.val() } , function(data) {
$("#jqueryReply").html(data).show().fadeOut(10000);
document.pmForm.pmTextArea.value='';
document.pmForm.pmSubject.value='';
$("#pmFormProcessGif").hide();
});
}
}
Here is a fiddle to see what's happening. http://jsfiddle.net/RKN39/
If you parse a value of the form to a variable in Jquery, you have to tell jQuery what value you need. With .val(), jQuery picks the value of your textfield.
var pmSubject = $("#pmSubject").val();
var pmTextArea = $("#pmTextArea").val();
var sendername = $("#pm_sender_name").val();
var senderid = $("#pm_sender_id").val();
var recName = $("#pm_rec_name").val();
var recID = $("#pm_rec_id").val();
var pm_wipit = $("#pmWipit").val();
Hope it works!
Why not serialize your form?
$( '#pmForm').on( "submit", function( event ) {
event.preventDefault();
var form_data = $( this ).serialize() ;
console.log(form_data);
var pmSubject = $("#pmSubject");
var pmTextArea = $("#pmTextArea");
var url = "../_Scripts/private_msg_parse.php";
if (pmSubject.val() === ""){
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type a subject.').show().fadeOut(6000);
} else if (pmTextArea.val() === "") {
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type in your message.').show().fadeOut(6000);
} else {
$("#pmFormProcessGif").show();
$.post(url, form_data, function(data) {
$("#jqueryReply").html(data).show().fadeOut(10000);
pmTextArea.val("");
pmSubject.val("");
$("#pmFormProcessGif").hide();
});
}
});