tags:

views:

48

answers:

1
if(!isset($_POST['JoinFaction'])) {

echo '<form method="post" action="'.$page_name.'"><dl id="sample" class="dropdown" align="left">'
    .'<dt><a href="#"><span>Recruiting Factions ['.$numrows.']</span>'
    .'</a></dt><dd><ul>';

while($faction_re = mysql_fetch_array($sql)){
echo '<li><a href="#">'.$faction_re['f_name'].''
    .'<span class="value">'.$faction_re['f_id'].'</span></a></li>';         
}

echo '</ul></dd></dl></td>'
    .'<td class="faction_bgcolour" align="center"><input type="image" '
    .'name="JoinFaction" value="JoinFaction" width="54" height="45" '
    .'src="images/global/game/faction/join_faction.png" /></td></form>';
  //get output as a variable to use in later code
  echo $selected_faction = '<span id="result"></span>'; 

} else { $selected_faction = '<span id="result"></span>';

echo '<div class="faction_text">Joined: '.$selected_faction.'.</div>';

}

when I:

echo $selected_faction;

in the if statement, it gets the right faction value (i'm using custom jquery drop down boxes by the way here).

The problem is that this id is not being passed to the else statement where i can update the database. I'm really not sure how I would pass the id on to the else statement.

echo $selected_faction is blank in the else clause

Any help would be greatly appreciated.

+1  A: 

You're going to need to send the content of that div back to your server with AJAX.

You could start learning here: http://api.jquery.com/category/ajax/

I suppose a good starting point might be: http://api.jquery.com/jQuery.post/

Michael Robinson
I've declared $selected_faction outside the block as you've stated, but it still returns = Joined: . / $selected_faction = ' ';How do i pass on the value inside the <span id="result"></span> to my else statement?
Callum Johnson
I'm sorry but I'm not entirely sure what you mean by the value inside the span?
Michael Robinson
Do you mean this line: `echo $selected_faction = '<span id="result"></span>'; `?
Michael Robinson
yeah, the javascript inserts the selected id in that span.
Callum Johnson
any ideas how I can solve my problem?
Callum Johnson
i've tried this, and it still doesn't display a value (when $selected_faction = '<span id="result"></span>';) outside the if !isset brackets. I think the problem is that jquery inserts the selected id inside: <span id="result"></span> when a drop down item is selected, i can't get this id into a php variable for me to use.
Callum Johnson
It's not going to. Edited answer.
Michael Robinson
thank you for all the help!
Callum Johnson