-
-
Save anonymous/6f36b242e9d7ebee3b56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body class= "metro"> | |
<h2>ENABLE/DISABLE AGENT(s)</h2> | |
<br> | |
<p>Checked boxes will enable agents</p> | |
<TABLE class="table striped hovered dataTable" id="dataTable"> | |
<thead> | |
<tr> | |
<th class="text-left"><INPUT type="checkbox" | |
onchange="checkAll(this);" name="chk[]" /></th> | |
<th class="text-left">Agent Id</th> | |
<th class="text-left">Agent Name</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<!-- | |
adding some more context to the input box will allow you to simplify your js | |
add a class that will be unique to all of the inputs and the id to the rel. This will make your js much simplier | |
--> | |
<td><input class="agent-checkbox" rel="123456" type="checkbox" checked /></td> | |
<td>123456</td> | |
<td>John Doe</td> | |
</tr> | |
<tr> | |
<td><input class="agent-checkbox" rel="654321" type="checkbox" /></td> | |
<td>654321</td> | |
<td>John Doe 2 </td> | |
</tr> | |
<tr> | |
<td><input class="agent-checkbox" rel="987654" type= "checkbox" checked /></td> | |
<td>987654</td> | |
<td>John Doe 3</td> | |
</tr> | |
</tbody> | |
</TABLE> | |
<button onclick="getCheckedRow()">Update</button> | |
<p id="invalid"></p> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> | |
<script type=text/javascript> | |
function enableDisableInDatabase(a_id, enabled) { | |
alert( a_id + ' ' + enabled ); | |
return; | |
var arr= {a_id: a_id, enable: enabled}; | |
$.ajax({ | |
type : 'POST', | |
url : "http://192.168.1.8:8080/SurveyApp3/enableDisableAgent", | |
data: JSON.stringify(arr), | |
dataType : 'html', | |
async : false, | |
contentType : 'application/json; charset=utf-8', | |
success : function(data) { | |
if (data === "Successful") | |
document.getElementById("invalid").innerHTML= "Updated Successfully"; | |
else { | |
console.log("Failed"); | |
document.getElementById("invalid").innerHTML = "Invalid agent id"; | |
} | |
}, | |
error : function(xhr, status, errorThrown) { | |
console.log(xhr); | |
console.log(status); | |
console.log(errorThrown); | |
} | |
}); | |
} | |
function getCheckedRow() { | |
//loop through all elements with agent-checkout class | |
$('.agent-checkbox').each(function(){ | |
//call the function passing the id via the rel and a boolean if checked or not | |
enableDisableInDatabase( $(this).attr('rel'), ( $(this).is(':checked') ) ); | |
}); | |
} | |
</script> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment