0

I can't figure this out. I have this HTML

<input type="text" class="studno"><input type="button" value="Check" class="chstudno">

How can I send this to PHP using JQuery/AJAX? I have this code but I think it's wrong

var boom = 'booming';

$(document).ready(function(){
$(".chstudno").click(function(){
$(".inup").html(boom);
studnoch();
});
});

function studnoch(){
var studno = $('.studno').val();
$.post("prochat.php", {studno: studno};
}

As for the php file, it's a simple command that will check if the input variable matches any thing on the database.

2 Answers 2

2

You probably meant:

$(".studno").click(function(){

Or:

$(".chstudno").click(function(){        

Instead of:

$(".check").click(function(){

check is the value not the class:

<input type="button" value="Check" class="chstudno">
Sign up to request clarification or add additional context in comments.

1 Comment

@Miles. I can't guess you know, can you tell us what is not working? EXACTLY.
0

Start off with a basic test: add a success function:

function studnoch() {
  var studno = $('.studno').val();
  alert('studnoch() has been called with studno=' + studno);
  $.post("prochat.php", {studno: studno}, 
    function(data, txt, xhqr) { alert('Ok, it worked'); }
  );
}

This should help you find out where you're going wrong...

BTW, it's probably a better idea to use an id for the input you want. This should make it unique:

<input type="text" class="studno" id="myinput">

Then retrieve it's value with:

$('#myinput').val();

Comments

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.