Are we allowed to use jQuery? I would like to use it for ajax and for manipulating the HTML in real-time without having to reload the page so many times.
a sample of the kind of thing I would like to do there looks like this. This is part of the system I'm writing at work, this code is copyrighted so no copying it from me!
Language: Javascript
<script type="text/javascript">
//confirm not safe
function checkForm() {
if($(';input:radio[name=safe]:checked';).val() == ';no';) {
return confirm("Are you sure this item is NOT safe to use?");
}
}
$(document).ready(function(){
var assetno = "";
//get the info for the asset children and output
$("#asset_num").bind("change", function(){
assetno = $(';#asset_num option:selected';).text();
$.post("./asset_child_info.php",{asset: assetno},function(data){
var vals = new Array();
var untrimed = new Array();
untrimed = data.split(",");
for(var i=0; i < untrimed.length; i++) {
vals[i] = $.trim(untrimed[i]);
}
//output children
$("#children").hide();
$("#children").empty();
var childrenList = "All these items have to be present:<br /><ol>";
for(var i=0; i < vals.length; i++) {
childrenList = childrenList + "<li>" + vals[i] + "</li>";
}
childrenList = childrenList + "</ol>";
$("#children").append(childrenList);
$("#children").fadeIn(';fast';);
});
});
});//end main func
</script>
The server side:
Language: PHP
<?php
include(';../../../bin/config/coninfo.php';);
$con = mysql_connect($server, $usrname, $pwd);
if(!$con) {
die(';Could not connect: '; . mysql_error());
}
$asset = xssFilter($_POST[';asset';]);
$retstring = "";
mysql_select_db(';ndms_admin';, $con);
$query = "SELECT name FROM equipment_new
WHERE assetcode=';{$asset}';
AND name!=';MAIN UNIT';";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$retstring .= $row[';name';] . ",";
}
//remove last comma
$retstring = substr_replace($retstring ,"",-1);
echo $retstring;
This gets the asset children from the database and displays them in a div without reloading the page. I would like to do something similar with the deleting a player section. I have some cool ideas there.
----------------------------------------------------------------------------------------
int get_random_number() {
return 4;
}