Uncaught TypeError: $(...).value is not a function when trying to send a value via JQuery

28,605

Solution 1

There is no function named value in jquery.

{ chat_message: $('#m').value() }

It should be -

$('#m').val()

Solution 2

$('#messages').load('send.php', { chat_message: $('#m').val() });

Share:
28,605
Vladimir Marenus
Author by

Vladimir Marenus

Just trying to learn some gamedev (for real, not the two-month "This is too hard" common 'gamedev' learner), and I'm sure I'll have inane questions along the way. Thank you, everyone who is / has / will helping / helped / help me!

Updated on April 06, 2020

Comments

  • Vladimir Marenus
    Vladimir Marenus about 4 years
    <!DOCTYPE html>
    <html>
    <head lang="en">
        <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
        <meta charset="UTF-8">
        <title>PHP socket chat</title>
        <style>
            * { margin: 0; padding: 0; box-sizing: border-box; }
            body { font: 13px Helvetica, Arial; }
            form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
            form input { border: 0; padding: 10px; width: 100%; margin-right: .5%; }
            form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
            #messages { list-style-type: none; margin: 0; padding: 0; }
            #messages li { padding: 5px 10px; }
            #messages li:nth-child(odd) { background: #eee; }
        </style>
    
    
    </head>
    <body>
    <ul id="messages"></ul>
    
    <form action="">
        <input type ="text" id="m" autocomplete="off" />
        <input type="submit" value="Submit" onclick="$('#messages').load('send.php', { chat_message: $('#m').value() });" />
    </form>
    

    I am seeing an

    "Uncaught TypeError: $(...).value is not a function"

    whenever I submit data, and I'm not sure why. I'm trying to send the data in the text field via POST to send.php.

    Any help would be appreciated, thanks!

  • Vladimir Marenus
    Vladimir Marenus about 9 years
    Well, don't I feel special. I'll accept your answer when it will let me. That's what I get for trying to learn pre-coffee...
  • Cthulhu
    Cthulhu about 8 years
    Hi, welcome to SO. Please don't just dump code as an answer, explain your thought to your fellow programmers. Cheers.
  • zasman
    zasman over 5 years
    This dude actually helped me