I'm relatively new to JQuery and Ajax, so am having some issues with using $.post(). I've had a look at some of the tutorials and documentation here, but none have really helped me with this issue.
I'm trying to use radio buttons to select a banner (for my online game). Upon selecting one, I would like the image to fade in below the buttons so the player can preview it before setting it as their preferred banner.
include_once(DIRNAME(__FILE__) ."/globals.php");
$_POST['banner'] = abs(@intval($_POST['banner']));
$_GET['view'] = abs(@intval($_GET['view']));
?>
<script src = "js/jquery/jquery-1.3.2.js" type = "text/javascript"></script>
<script language = "javascript" type = "text/javascript">
//alert("Javascript is a pain");
function changeBanner(theBanner) {
alert(theBanner);
if(theBanner == 0) { alert("No banner to show."); }
else {
$.post("choosebanner.php", { view: theBanner },
function(data) {
$('#viewbanner').html(data);
}
);
}
}
</script>
<?php
print "<p>Here, you can change the current banner you see at the top of the page!</p>
<p>Select one from the dropdown below. You will see the banner when you select it.</p>
<p>
<form action = '' name = 'bannerChoice' method = 'post'>";
$value = 1;
while($value < 4) {
print "<input type = 'radio' name = 'banner' id = 'bannerID' value = '". $value ."' onClick = 'changeBanner(this.value);' />Banner ". $value;
$value++;
}
print "<br />
<input type = 'button' name = 'subBanner' value = 'Choose Banner' onClick = \"saveBanner();\" />
</form>
</p>";
print "<div id = 'viewbanner'></div>";
if($_POST['view']) {
print "view: ". $_POST['view'] ."<br />";
if(!is_numeric($_POST['view'])) {
print "<p style = 'color:#FF0000'>Invalid banner selected.</p>";
}
else {
$banners = array(1 => "grungebanner.php", 2 => "banner3.png", 3 => "banner.png");
$showBanner = "crysis/". $banners[$_POST['view']];
$showBanner2 = "<img src = '". $showBanner ."' alt = 'Banner' />";
print $showBanner2;
}
}
$h->endpage();
?>
I don't understand why, when I click a radio button, the data is not processed and the image doesn't appear underneath the buttons.
If anyone can enlighten me as to how to fix this problem, it will be highly appreciated.