when we choose one radio button and click the button, progress bar should be updated each time

I need to create a simple web page which includes three radio button, and three progress bar for each radio button, and one button, if we choose one radio button and click the button, progress bar which belongs to clicked radio button should be updated each time with using ajax, who can help with this issue ?
Giyosjon JumayevAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Here is a sample on how to do this. Note this sample uses setInterval() to simulate an AJAX call
CSS
.my-progress-bar {
  display: none;
  width: 300px;
  text-align: center;
  line-height: 2em;
  border: 1px solid black;
  height: 2em;
  overflow: hidden;
  position: relative;
}
.my-progress-bar span {
  display: block;
  position: absolute;
  right: 100%;
  background: green;
  height: 2em;
  z-index: 50;
  width: 100%;
}
.my-progress-bar b {
  position: relative;
  z-index: 100;
}

Open in new window

HTML
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="1" data-progress="progress1">
  <div class="my-progress-bar" id="progress1">
    <span></span>
    <b></b>
  </div>
</div>
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="2" data-progress="progress2">
  <div class="my-progress-bar" id="progress2">
    <span></span>
    <b></b>
  </div>
</div>
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="3" data-progress="progress3">
  <div class="my-progress-bar" id="progress3">
    <span></span>
    <b></b>
  </div>
</div>
<button class="btn btn-primary">Go</button>

Open in new window

jQuery
$(function() {
  $('button').click(function(e) {
    e.preventDefault();
    var selected = $('.progress-radio:checked');
    $('.progress-bar').hide();
    if (selected.length) {
      // simulate AJAX call here
      var perc = 0;
      var pb = $('#' + selected.data('progress'));
      var slider = pb.find('span');
      pb.css({display: 'inline-block'});
      var text = pb.find('b');
      var intv = setInterval(function() {
        if (perc >= 100) clearInterval(intv);
        text.text(perc + '%');
        var diff = 100 - perc;
        slider.css({right: diff + '%'});
        perc += 10;
      }, 500);
    }
  });
});

Open in new window


Working sample here
0
Giyosjon JumayevAuthor Commented:
Thanks for your sincere help, but when I choose radio button and click the button, progress bar should be updated its value to one only each time, if I click the button 10 times, progress bar should change its value to 10
0
Julian HansenCommented:
HTML
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="1" data-progress="progress1">
  <div class="my-progress-bar" id="progress1">
    <span></span>
    <b></b>
  </div>
</div>
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="2" data-progress="progress2">
  <div class="my-progress-bar" id="progress2">
    <span></span>
    <b></b>
  </div>
</div>
<div>
  <input type="radio" class="progress-radio" name="myRadio" value="3" data-progress="progress3">
  <div class="my-progress-bar" id="progress3">
    <span></span>
    <b></b>
  </div>
</div>
<button class="btn btn-primary go">Go</button>
<button class="btn btn-danger reset">Reset</button>

Open in new window

jQuery
$(function() {
  $('button.reset').click(function(e) {
      e.preventDefault();
      $('.my-progress-bar').data('perc', 0);
	  $('.my-progress-bar span').css({right: '100%'});
	  $('.my-progress-bar b').text('');
  });
  $('button.go').click(function(e) {
    e.preventDefault();
    var selected = $('.progress-radio:checked');
    if (selected.length) {
      var pb = $('#' + selected.data('progress'));
      var perc = pb.data('perc') || 0;
      perc += 10;
      if (perc <= 100) {
        pb.css({display: 'inline-block'});
        var slider = pb.find('span');
        var text = pb.find('b');
        var diff = 100 - perc;
    
        text.text(perc + '%');
        slider.css({right: diff + '%'});
		pb.data('perc', perc);
      }
    }
  });
});

Open in new window

Updated sample here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Giyosjon JumayevAuthor Commented:
Thanks so much for your help. It is as I want, I'm so greatful
0
Julian HansenCommented:
You are welcome,

If you are satisfied with the answer, please could you close the question.

If you are having trouble with this process - post back here.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.