Reputation: 864
I have a JavaScript function for a HTML button click event in aspx page and a server method in the page code-behind. When the HTML button is clicked by the user it will be processed, and the button will display an answer.
How do I get the button label to be updated, as it is using AJAX?
When I try to set the update somewhere, the page does not update the button. The text box updates work fine. As one can see from the code below, btnDivide
has a set value of "Get Weather" at the moment, but I need to change it once the user is done processing.
<script type="text/javascript">
<![CDATA[
// This function creates an asynchronous call to the service
function makeCall(operation){
var n1 = document.getElementById("num1").value;
var n2 = document.getElementById("num2").value;
// If user filled out these fields, call the service
if(n1 && n2){
// Instantiate a service proxy
var proxy = new Service();
// Call correct operation on vf cproxy
switch(operation){
case "gridOne":
proxy.Calculate(AjaxService.Operation.getWeather,n1,n2,
onSuccess, onFail, null);
btnDivide.value = "TestNewValue";
break;
case "gridTwo":
*******
</script>
<style type="text/css">
#result
{
width: 1010px;
}
</style>
</head>
<body>
<h1>Ajax TicTacToe</h1>
<p>Major City: <input type="text" id="num1" onclick="return
num1_onclick()" /></p>
<p>Country: <input type="text" id="num2" onclick="return num2_onclick()"
/></p>
<br />
<input id="btnDivide" type="button" onclick="return makeCall('gridOne');"
value="Get Weather" />
Upvotes: 3
Views: 227
Reputation: 864
function onSuccess(mathResult){
document.getElementById("result").value = mathResult;
document.getElementById("btnDivide").value = "test";
}
Upvotes: 0
Reputation: 9092
You need an event handler to endRequest event take a look here: http://msdn.microsoft.com/en-us/library/bb383810.aspx
Upvotes: 2