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();


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


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

    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.

Recommended Answers

All 5 Replies

var name = $("#name").val();
Member Avatar

Hmm. Does 'name' as a varname cause issues? I think I ran into this a while ago.

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

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.


    // your code would go here


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.