1

I want to pass a value from a user input in a html to jQuery.ajax. Here's the code for my JS file:

jQuery(document).ready(function() {
    jQuery.ajax({           
        type: 'POST',
        url: 'myurl.aspx',
        data: {
            action: 'something', 
            count: txtCount
        }
    });
});

and here's my html file:

Count: <input type="text" id="txtCount" name="count" />
<input id="btnSubmit" type="Submit" value="Submit" />
<div> output somewhere here</div>

My javascript is working, I just removed some of the codes since i'm just pointing out on how to pass the values from the html to my ajax. I'm trying to develop a Chrome Packaged App.

4
  • api.jquery.com/val Commented Mar 21, 2016 at 9:16
  • i know the .val().. i'm new to jQuery and ajax, i don't know how to make it work... i tried different things, creating function inside the function and even inside the ajax, still not working,.. i started jQuery 2days ago by the way Commented Mar 21, 2016 at 9:18
  • count: $('#txtCount').val() Commented Mar 21, 2016 at 9:18
  • thanks for the immediate reply, hmm, your comment is correct, but i get error, and i don't know how to debug on the runtime Commented Mar 21, 2016 at 9:22

1 Answer 1

1

I guess you are looking for something like this:

jQuery.ajax({           
    type: 'POST',
    url: 'myurl.aspx',
    data: {
        action: 'something', 
        count: $("#txtCount").val();
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

the comment answered it first so i'll just vote 1 up for you :) thanks for the reply sir.

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.