0

I am trying to pass a value from a hidden input using ajax but console says whatever im doing is not a function

Uncaught TypeError: "#name".val is not a function page.php:35

which is this line : var name = ("#name").val();

html:

<input type='hidden' value='$newname' id='name'>

ajax:

var name = ("#name").val();

$.ajax({
    type: "POST",
    url: "declineRequest.php",
    data: "name="+name,
    success:  function(data){
      alert("Request Declined!");
    }
});

why does the error occur? what did i do wrong? tq.

4
Contributors
5
Replies
29
Views
2 Years
Discussion Span
Last Post by nadiam
0

i changed it multiple times so its not name = name but i still get the same error in the console.

var full = ("#fullname").val();

Uncaught TypeError: "#fullname".val is not a function

0

You're using jQuery... so you have to call the jQuery library using $ or jQuery like $("#fullname").val() or jQuery("#fullname").val().

Also, where is the JavaScript code at on the page? Did you put in in the head of the page, or towards the bottom of the body?
If the JavaScript runs before the elements have been loaded, then you'll run into problems.
If you want to keep it in the head, you'll need to tell it to wait until the DOM has finished loading.

$(document).ready(function(){

    // your code would go here

});
0

oh ya! crap. after looking at the code for like ever. totally didn't realize that. thank you!pixelsoul and pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.