www.webdeveloper.com
Results 1 to 3 of 3

Thread: A problem with the JavaScript code on my website

  1. #1
    Join Date
    Oct 2010
    Posts
    11

    A problem with the JavaScript code on my website

    Hi,
    I have a problem with the JavaScript code on my website.
    My website page with the code is: yeparticles.com/order
    I'm talking about the words, price and days calculator at the bottom of page (below the table).


    The problem is that when I'm selecting the word count in the rows of the table, it doesn't affect the number of words, price and days in the calculator immediately, but only after that I'm typing on another field.

    Here is the code of the calculator:

    Code:
    function costTimeCalculator(totalwords)
    {
    var cost=totalwords*0.015;
    cost=cost.toFixed(2);
    var  time=2;
    if(totalwords>5000)
    {
    time=Math.ceil((totalwords/2500));
    //if((totalwords%2500)==0)
    // time=time-1;
    }
    if(totalwords>0)
    {
    $('#words').text(CommaFormatted(totalwords)+" Words");
    $('#cost').text("$"+cost);
    $('#time').text("~"+time+" Days");
    //assign to hidden variables
    $('#words_value').val(totalwords);
    $('#cost_value').val(cost);
    $('#time_value').val(time);
    }
    else
    {
    $('#words').text('0 Words');
    $('#cost').text('$0');
    $('#time').text('0 Days');
    //assign to hidden variables
    $('#words_value').val('');
    $('#cost_value').val('');
    $('#time_value').val('');
    }
    }
    How can I make that the calculator will be updated immediately after that I'm selecting the word count in the table (without having to type on another field)?

    Thanks,
    Steve
    Last edited by SteveJo; 08-08-2013 at 06:21 AM.

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Change your onblur function with a onchange function
    Code:
    $(document).ready(function(){
         //...
    
         $('.wname,.aname').on('blur',function(){   // To repace with a 'change'
              //...
              costTimeCalculator(0);
         });
    });
    Then the calculator will update the datas after the change of the selected option without waiting the onblur event on the select.
    Last edited by 007Julien; 08-08-2013 at 07:22 AM.

  3. #3
    Join Date
    Oct 2010
    Posts
    11
    Great. Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles