serializeArray to load form in a div.
So I am working on changing my website from iframes to divs, in which I will need to use javascript to make this happen as far as forms loading into a div rather than moving on in a iframe. But I'd rather use jquery personally
.
So I made my main.php more div like by applying the $('#frame').load('fight.php'); function which has worked wonders so far.
Now I am working on a new file I call fight.php in which case users can fight monsters and increase their level. There is the better understanding of what I want to do, now to move to the problem...
Here is the jquery function I am using to load a
submitted form into the FightDiv with the data in the
submitted form:
- <script>
- function running(){
- $("#FightDiv").load("fight.php",
- $("#FightForm").serializeArray());
- }
- </script>
Next I will be showing what I am posting into and the form I am getting the data from:
- print"<div id=\"FightDiv\">"; //the div that will be refreshed with new data after submitted
- echo "<p>Name - Level<br /></p>";
- echo "<form id=\"FightForm\" method=\"post\">";// the form to be submitted
- echo "<p><select class=\"select\" name='Name'>";
- if($_COOKIE['Monstername'])
- {
- $Name = $_COOKIE['Monstername'];
- $Query = mysql_query("SELECT * from Monsters where Name='$Name' limit 1") or die("ZOMG no cookie monster");
- $QMonster = mysql_fetch_array($Query);
- if($QMonster['Zone'] == $Zoneloc)
- echo "<option value=\"$_COOKIE[Monstername]\">$_COOKIE[Monstername] (Previous fight)</option>";
- }
- $Monster1 = "SELECT * from Monsters where Zone='$Zoneloc' order by Level asc";
- $Monster2 = mysql_query($Monster1) or die("Could not select Monsters from under your bed!");
- while ($Monster3 = mysql_fetch_array($Monster2))
- {
- echo "<option value=\"$Monster3[Name]\">$Monster3[Name] - $Monster3[Level]</option>";
- }
- echo "</select><br />";
- echo "<input class=\"button\" onclick=\"running()\" type='submit' name='Fight' value='Fight Monster' /></p></form><br />";
- print"</div>";
After the user submits it will go to a php function statement set off as if(isset($_POST['Fight'])).
But this is where I get the problem. When I do submit the form to move on and fight the monster, I fail to move on and fight the monster. The end result is the fight.php page only refreshing the whole parent and returning to the original form.
Thank you to anyone who finds the time to read this and help me find my problem.