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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With