Link to home
Start Free TrialLog in
Avatar of Giyosjon Jumayev
Giyosjon Jumayev

asked on

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 ?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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
Avatar of Giyosjon Jumayev
Giyosjon Jumayev

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much for your help. It is as I want, I'm so greatful
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.