Page 1 of 1
is AJAX what I gotta do for the following.....
Posted: Sun Jun 11, 2006 2:24 am
by Charles256
I have a planet name...if the name has never been changed before user can click on it, change it's name, then when he confirms it the name changes on the page...
Posted: Sun Jun 11, 2006 5:37 am
by Chris Corbyn
There's no reason why you can't have the page just reload but yes it does sound like AJAX could make it look better. Just make sure they hyperlink with onclick="" actually leads somewhere useful for backward compatibility.
Posted: Sun Jun 11, 2006 6:14 am
by Charles256
eh.not AJAX but what I ended up doing...
Code: Select all
function change(name,system)
{
var new_name=prompt('Please enter a new planet name below:',name);
location.href='index.php?nav=game&page=game&old='+name+'&new='+new_name+'&system='+system+'';
}
Code: Select all
if (isset($_GET['old']))
{
$change=check_planet_name($_GET['system'],$_GET['old'],$_GET['new']);
if ($change)
{
change_planet_name($_GET['system'],$_GET['old'],$_GET['new']);
}
}
check planet name and change planet name functions...
Code: Select all
function check_planet_name($system,$old,$new)
{
if(!ctype_digit($system))
{
echo "System must be numerical.";
return FALSE;
}
if (strlen($new)>100)
{
echo "New name must be less than 100 charecters.";
return FALSE;
}
else
{
// do query to see if name can be changed.
// function to make sure it's safe to change name.
// assuming everything checks out...
return TRUE;
}
}
function change_planet_name($system,$old,$new)
{
//query to change name and make it so it can't be changed again.
}
and for informational purposes..what the link looks like that they click on in the planet display... just a snippett
Code: Select all
$display.="<a href=\"javascript:change('".$test->planet_name."',$test->system_id)\">".$test->planet_name."</a>";
not the most elgant solution probably, but definitely functional.
Posted: Sun Jun 11, 2006 6:28 am
by Chris Corbyn
It won't work with JS disabled.
A better approach is:
<a href="somewhere_for_no_js_clients.php?args" onclick="doSomethingForOtherBrowsers(); return false;">Click</a>
Posted: Sun Jun 11, 2006 6:33 am
by Charles256
so the logic being if they got js enabled the onclick will over ride everything else and they'll never actually get to the link that non js people will use,right? it won't be as nearly as convient for the non js people but you got a good point.. suppose I need to make this accessible if I want people to play it.

Other than that, what'd ya think of my solution? good enough?