I am currently working on setting up a JQuery Progress Bar that updates when the user submits a form. The code I am debugging is basic and consists of:
<body>
<form id="form1" method="GET" runat="server">
<div>
<h1>Test</h1>
<input type="submit" value="Start Test"/>
</div>
</form>
<div id="progressbar"></div>
<script type="text/javascript">
$("#progressbar").progressbar({
value: 25
});
$("#progressbar > div").css({ 'background': 'Green' });
$(document).ready(function () {
$("#form1").submit(function () {
$("#progressbar").progressbar({ value: 75 });
});
});
</script>
</body>
This simple form initializes the progress bar at 25% and then triggers a .submit function to update it to 75%. However, the updated value only flashes momentarily upon clicking the Submit button repeatedly.
My main question is: How can I keep the updated value displayed after it has been changed by the .submit function?
Thank you in advance!
UPDATE: I appreciate the advice from @charlietfl :-) Still new to posting here :-)
Below is the AJAX-based code I have implemented...
<body>
<form id="form1" method="GET" runat="server">
<div>
<h1>Test</h1>
<input type="submit" value="Start Test"/>
</div>
</form>
<div id="progressbar"></div>
<script type="text/javascript">
$("#progressbar").progressbar({
value: 25
});
$(document).ready(function () {
$("#form1").submit(function () {
$.ajax({
url: "JQueryProgressTest.aspx/GetProgress",
type: "GET",
success: function (data) {
$(".selector").progressbar({value: data});
}
});
});
});
</script>
</body>
The progress bar is still not updating...and the value does not even flash anymore.
Appreciate any help!
Bob
FINAL UPDATE: To get the callback from the ASPX page to work, I needed to include some JSON elements. Below is the complete code that is now functional for others who may need it:
ASPX Code-Behind:
public partial class JQueryProgressTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static int GetProgress()
{
// Insert any code to update the progress bar here
return 50;
}
}
And the body of the ASPX page itself:
<body>
<form id="form1" method="GET" runat="server">
<div>
<h1>Test</h1>
<input type="submit" value="Start Test"/>
</div>
</form>
<div id="progressbar" style="border-color: lightgreen;"></div>
<script type="text/javascript">
$("#progressbar").progressbar({
value: 25
});
$("#progressbar > div").css({ 'background': 'Green' });
$(document).ready(function () {
$("#form1").submit(function (event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "JQueryProgressTest.aspx/GetProgress",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#progressbar").progressbar({ value: response.d });
},
failure: function(response) {
alert("Error in calling Ajax:" + response.d);
}
});
});
});
</script>
</body>
Thanks once again to @charlietfl for all the guidance!