is AJAX what I gotta do for the following.....

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

is AJAX what I gotta do for the following.....

Post 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...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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>
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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. :-D Other than that, what'd ya think of my solution? good enough?
Post Reply