I was trying to make jquery-ui progress bar which shows progress with filling inputs in form. My code is as following:
html:
<div id="progress" class="progress"></div>
//form and inputs
script:
$(document).ready(function(){
var elementcount = document.getElementById("events").length;
var totallength = 100;
var relativelength = totallength/elementcount;
var initial = 0;
$('#progress').progressbar({
value: initial,
});
$('#events').find(':input').each(function(){
$(this).change(function(){
if($(this).val()==""){
var value = initial - relativelength;
$('#progress').progressbar("value",value);
initial = value;
}
else{
var value = initial + relativelength;
$('#progress').progressbar("value",value);
initial = value;
}
});
});
});
In above code I have first counted no. of elements in the form and set the relative length(the length to be increased for each filled input). The progress bar is increased for change in input value. If input value is empted(i.e. blank), then it is decreased.
This works fine but the problem is that it detects change every time in change in input. So if I fill input and fill it second time, then again the progress bar is increased.
Is there any solution by which I can detect the first time change in input ans stop progress bar progressing after that change?