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?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.