0
var studno = $('#studno').val();
$(document).ready(function () {
    $('.go').click(function () {
        $('.inup').load('prochat.php', {
            studno: studno
        });
    });
});

I have this code and it's supposed to send the value of studno into prochat.php but everytime it does it only says undefined. Can anyone explain?

3
  • add alert(studno) before $('.inup').load('prochat.php', studno:studno});, what value is in the alert? Commented Jun 24, 2012 at 9:08
  • Is it just me, or it's almost like your previous question ? Commented Jun 24, 2012 at 9:20
  • you are basically reading the value once, when the script loads, that's why there is no #studno element yet, so you keep getting undefined.. Commented Jun 24, 2012 at 14:03

5 Answers 5

2

Try this:

$(document).ready(function(){
    $('.go').click(function(){
        var studno = $('#studno').val();
        $('.inup').load('prochat.php', {studno:studno});
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

$(document).ready(function(){

    $('.go').click(function(){
        var studno = $('#studno').val();
        $('.inup').load('prochat.php', {studno:studno});
    });
});

2 Comments

Thanks for the answer. I'll just accept it when after 11 minutes (cause that's what stack overflow says. lol)
This will always pass the same value though
0

Never mind. Turns out this works

$('.inup').load('prochat.php', {studno: $('#studno').val()});

Comments

0

These could be possible reasons:

  1. at the line where you are assigning the value to studno, the value of studno might be undefined
  2. #studno is not defined in the html

possible solutions:

-. try assigning the value within the click function:

like this:

$('.go').click(function(){
    studno = $('#studno').val();
    $('.inup').load('prochat.php', {studno:studno});
});

-. make sure that the element with id studno exists in the html document

Comments

0

This should work better:

$(document).ready(function () {
    $('.go').click(function () {
        $('.inup').load('prochat.php', {
            studno: $('#studno').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.