开发者

Jquery not updating .val first time round?

开发者 https://www.devze.com 2023-03-20 12:29 出处:网络
I have been doing the booking form on this website here. http://offline.raileisure.com/ if you fill in the booking form on the right hand side.. click extras and add some extras

I have been doing the booking form on this website here. http://offline.raileisure.com/

if you fill in the booking form on the right hand side.. click extras and add some extras

click get price to get the popup window...

You see where is says "Base Accomodation Price comes to £"

Well the first time it doesn't bring the pr开发者_运维技巧ice up (although it is setting the $('#bpriceinput').val(data);

if you click away to disappear the popup and click get price again. "Base Accomodation Price comes to £" now has the price...

IT just doesn't want to appear first time... is it because i am updating too close the the window popping up ??

I am baffled and spent 2 hours on this silly bug

Any help will be hugely appreciated

Thanks

Lee


The problem is that the AJAX call is made and that's asynchronous. In the meantime you're setting the 'comes to ...' text, but the data isn't available yet.

The second time, the data from the first time is available and shows that one, so it's still not correct.

    $.post("getprice.php", { unit: $('input[name=property]:checked').val() , date: $('#car').val() + $('#smh').val(), duration: $('input[name=duration]:checked').val()  } ,function(data){

        $('#bpriceinput').val(data);

        $('div[name=price]').html("Total Price: �" + ((parseFloat(data, 10) + extras)).toFixed(2));

        $('#btotalpriceinput').val(((parseFloat(data, 10) + extras)).toFixed(2));

    }); // <-- what if you move this line to the end of the calculation (i.e. line 551)


The line 546 $('#extrasinfo').html($('#extrasinfo').html() + "<br><br>Total for Extras comes to £" + extras + "<br>Base Accomodation Price comes to £" + $('#bpriceinput').val());

Is fired before the callback of your POST request has finished. You should add this line inside the callback. Also, the "Get Price" button stays disabled until you have selected everything and the clicked on the calendar again.

0

精彩评论

暂无评论...
验证码 换一张
取 消