is AJAX what I gotta do for the following.....
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
is AJAX what I gotta do for the following.....
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...
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
eh.not AJAX but what I ended up doing...
check planet name and change planet name functions...
and for informational purposes..what the link looks like that they click on in the planet display... just a snippett
not the most elgant solution probably, but definitely functional.
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']);
}
}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.
}Code: Select all
$display.="<a href=\"javascript:change('".$test->planet_name."',$test->system_id)\">".$test->planet_name."</a>";- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
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?