Paweł Skaba Paweł Skaba - 4 years ago 103
Javascript Question

jquery val not passing data

I've got several input fields and such jquery code:


var amount1=$('.product-addon-wesprzyj-autora input').val();
var amount2=$('#pa_kategoria-cenowa').val();
var amount3=$('.quantity .qty').val();
var fractal=0.01;
var Total=(amount1*amount2*fractal*amount3)+(' PLN');
$('.product-addon-kwota-dla-autora input').attr('value', Total);


Strange thing is that jquery code works. In real time in changes values in my inputs, BUT after clicking sumbit, value from '.product-addon-kwota-dla-autora input' seems to be empty in database. Why is that? is there any way of pushinig this code to work? If i will type via keyboard data into that field, everything works. ANy ideas what is here wrong?

Answer Source

With the code you provided, I am not quite sure what your problem is. It could be a problem in your server side code where you save the data to the table. You need to debug and that find out.

But make sure that you are setting the form values properly so that your server side code will have the correct data from the form. You may consider using the val() method to set value.

$('.product-addon-kwota-dla-autora input').val(Total);

Also , when you read values from form inputs and use it for numeric operations, Consider converting the type to a numeric version by using parseFloat() or parseInt()

var Total=parseFloat(amount1)*parseFloat(amount2)*parseFloat(fractal)
                                                         *parseFloat(amount3)+(' PLN');

Also, You may inspect your browser's network tab to see what data your browser is posting to the server code. That should help you to understand where your problem is.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download