JQuery val() returns empty string
Check that id 'Discount' is unique.
When putting multiple forms on a single page I leave the 'name' alone but always prefix the id of the 'form' element to the id of each 'value'.
Saves me alot of headaches.
Daren's answer definitely hit the nail on the head.
However, there are times when you want to return the value of multiple elements that have the same ID. (Note: IDs should be unique. Classes, on the other hand, don't need to be unique.)
To accomplish this you need to iterate with the .each()
method. Most jQuery methods that return an object implicitly iterate. .val()
returns a string, not an object. Because of that, it needs an explicit iteration loop.
You can do use the .each()
method like this.
$('.discount').each(function(){
$(this).val()
});
Please note that I changed the OP's ID to a class so that it is correct HTML.