0

How do you get the value of an html element attr for an ajax call?

my code:

$('#manager_pass').submit(function(evt){ 

    evt.preventDefault();

        $.ajax({

            url: App.managerpassURL,
            data: {
                ????????????
            },
            dataType: 'json',
            type: 'POST',
            success: function(r){
                box_2.animate({'top':'-250px'},500,function(){
                overlay.fadeOut('fast');
                    $('.action_wrapper').fadeOut(1000, function(){
                            $('.form').fadeIn(1000);
                    });
                });
            }


        });

});

I need to get the value from here

<input type="text" name="managerPassword" value="" class="man_code">

Thanks

1
  • I need to get the value from my input field inside my data object data: { ???????????? }, Commented Sep 26, 2012 at 11:47

3 Answers 3

1

Something like this if you want to send JSON:

JSON.stringify({ "pass" : $('input[name="managerPassword"]').val() })

Of course make sure its secured if you want to send a password!

Sign up to request clarification or add additional context in comments.

9 Comments

data: { JSON.stringify({ "pass" : $('input[name="managerPassword"]').val(); }) },
You should try data : JSON.stringify({ "pass" : $('input[name="managerPassword"]').val() })
not working :( data : JSON.stringify({ "pass" : $('input[name="managerPassword"]').val() }),
What's the error? can you try printing to the console console.log(JSON.stringify({ "pass" : $('input[name="managerPassword"]').val() })) just before you are calling $.ajax and tell us what you see?
success: function(r){ box_2.animate({'top':'-250px'},500,function(){ overlay.fadeOut('fast'); $('.action_wrapper').fadeOut(1000, function(){ $('.form').fadeIn(1000); }); }); }
|
0

If you specify an id attribute on your input element, you can do the following to get the value in js:

document.getElementById('exampleid').value

Comments

0

$('#manager_pass').submit(function(evt){

evt.preventDefault();
var passtxt=$('input:text[name=managerPassword]').val();
    $.ajax({

        url: App.managerpassURL,
        data: {
            passtxt:passtxt
        },
        dataType: 'json',
        type: 'POST',
        success: function(r){
            box_2.animate({'top':'-250px'},500,function(){
            overlay.fadeOut('fast');
                $('.action_wrapper').fadeOut(1000, function(){
                        $('.form').fadeIn(1000);
                });
            });
        }


    });

});

1 Comment

stackoverflow.com/questions/503627/… try in this way it may help you if JSON.stringify does not work

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.