خرید بک لینک
Hi, im working on a progress bar. I have the bar working on form submit. However in testing if i have an error on the form ( such as forgot required field) then the js still executes and i dont want that of course.

So how do i tell js that if there is an error on the form, dont start?

Im thinking ill have to trap that on the server side and then pass down a value to js from php, is that right?

I was hoping i could set a flag on the server side and then just refresh the page or use ajax... but i really would like to keep this easy and not involve another php file and ajax in the mix. mmmmm...

here is the code:

html:

Code:


    <div id="progressBar"><div></div></div>

js: we are ruing the progress bar option instead of the countdown option :)


Code:


$(document).ready(function(){

    $("input[name='vidfile[]']").change(function(){

        var t = this.files[0].size;   

        var sec = getseconds(t);
       
        var dispopt = {/literal} '{$dispopt}' {literal};
       
        if(dispopt == 'count')
        {

          startprogress(sec); //countdown opt
       
        }else{
           
              var maxsec = parseInt(sec);
              var zippo = 0;
       
              startProgressBar(zippo, maxsec, $('#progressBar')); //progress bar option
             
              }//close else
  });
});

/* progress bar */

function startProgressBar(begin, totaltime, $element)
{
   
  $("form[name='viduploadForm']").submit(function(){

    var defval = parseInt(begin);
    var totaltimesec = parseInt(totaltime); //total secs to do the upload
 
    //default first appearance   
    var progressBarWidth = defval * $element.width() / 100;
    $element.find('div').animate({ width: progressBarWidth }, 500).html(defval + "% ");
   
    startTimerBar(totaltime, $element);
 
  });
 
   
}//close function


function startTimerBar(howlong, $element)
{
   
    var totalsec = parseInt(howlong);  //total sec it will take
    var count = 0;
 
    function timerbar()
    {
       
      count = count + 1;
       
      if(count < totalsec)
      {
        //continue the loop
        progressBarWidth = count * $element.width() / totalsec;
        $element.find('div').animate({ width: progressBarWidth }, 500).html(count + "% ");
         
      }else{
             
              clearInterval(sb);
         
            }//close else

  };
  timerbar(); 
  var sb = setInterval(timerbar, 1000);
   
}//close function

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 12 دی 1396 ساعت: 13:37

صفحه بندی