3

I have the following Javascript:

var paymentForm = $('#payment_form, .payment-invoices-container');

var ocodes = paymentForm.find('[name="ocodes"]:enabled');


alert(ocodes);


$.post( 'https://URL/ajax-json.do?ocode='+ocodes+'&ocodes='+ocodes, function( data ) {
if (data.hasOwnProperty('dynamicJavascriptUrl')) {
     var script = document.createElement('script');
    script.src = data.dynamicJavascriptUrl;
    $('#credit_card').append($(script));
}
}, "json");

What I want to do is, to take the values from [name="ocodes"] in #payment-form and append it to my $post url but it doesnt seem to get the value because it returns [object Object ].

Can anyone point me in the right direction or give a hint as to what is wrong I would appreciate it :)

1 Answer 1

3

Call the val() method on the jQuery object.It will give you the current value of the first element in the set of matched elements

var ocodes = paymentForm.find('[name="ocodes"]:enabled').val();
alert(codes);

Assuming paymentForm.find('[name="ocodes"]:enabled') expression is returning a valid jQuery object with a value property in it ( Ex: texboxes, radio buttons,check boxes etc..)

Here is a working sample

If your jQuery selector is returning a div /span and you want the content inside it, you may try html() or text() methods as needed. But remember, they return more than just the value.you may get some html content as well depending upon your HTML setup. So use them as suited by your HTML markup.

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

Comments

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.