Skip to content

Instantly share code, notes, and snippets.

@benguthrie
Created November 6, 2011 02:26
Show Gist options
  • Save benguthrie/1342371 to your computer and use it in GitHub Desktop.
Save benguthrie/1342371 to your computer and use it in GitHub Desktop.
2 Stage JQuery Form
<?php session_start();
require_once('inc/inc.php');
// Build schools
$sql = "select id_institution,inst_name from institution";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$ddi = "<select id='inst'>";
for($a=0;$a<$count;$a++)
{
$ddi .= "<option value='".mysql_result($result,$a,"id_institution")."'>".mysql_result($result,$a,"inst_name")."</option>";
}
$ddi.="</select>";
$startYear = 1946;
$endYear = 2011;
$ddy = "<select id='year'><option value='0'>-None-</option>";
for($a=$endYear;$a>$startYear;$a--)
{
$ddy .= "<option value='".$a."'>".$a."</option>";
}
$ddy.="</select>";
// Define the sports
$dds = "<select id='sport'><option value=''>-None-</option><option value='2'>Sports Info</option><option value='1'>Administration</option><option value='0' selected>Football</option></select>";
$ddr = "<select id='role'><option value=''>-None-</option><option value='0' selected>Coach</option><option value='1'>Player</option></select>";
?>
<!DOCTYPE html><html><head><title>Add Staff</title>
<script type="text/javascript" src="jquery.form.js"></script>
<script type='text/javascript'>
// wait for the DOM to be loaded
//
/*
$(document).ready(function() {
console.log("hhhh");
$('#phaseTwo').ajaxForm(function(data) {
console.log("thetest",$("#thetes").val());
$("#addA").append(data);
console.log("oyes");
console.log(data);
});
});
*/
function phaseTwo(){
console.log("hhhh");
console.log($("#phase2"));
console.log("thetest",$("#thetest").val());
$("#addA").append("1.");
$("#phaseTwo").ajaxForm(function(data) {
$("#addA").append("2.");
$("#addA").append("data",data);
console.log("oyes");
});
}
function AddStaffByInstitution(){
// alert("test");
var instID = $("#inst").val();
var year = $("#year").val();
var sport = $("#sport").val();
var role = $("#role").val();
var wins = $("#w").val();
var losses = $("#l").val();
var ties = $("#t").val();
var names = $("#names").val();
names = names.replace(" ,",",");
names = names.replace(", ",",");
names = names.replace(" "," ");
var narr = names.split(",");
console.log("Inst ID: "+instID+" Year: "+year+" sport: "+sport+" role: "+role+" wins: "+wins+" losses: "+losses+" ties: "+ties + " names: "+narr[0]);
var thecount = narr.length;
console.log(thecount);
var str = '<br/><h2>Team</h2>'
+'Team ID: <input type="text" id="instID" value="'+instID+'"></input><br/>Wins: <input type="text" value="'+wins+'"><br/>Losses: <input type="text" value="'+losses+'"></input><br/>Ties: <input type="text" value="'+ties+'"></input><br/>Sport ID: <input type="text" value="'+sport+'"></input><br/>'
+'<table><tr><th>First</th><th>M</th><th>Last</th><th>Jr?</th><th>Nickname</th><th>Start Year</th><th>End Year<th>sport ID</th><th>role</th></tr>';
for(a=0;a<thecount;a++)
{
var tnarr = narr[a].split(" ");
console.log(a + " " + tnarr[1]);
console.log(a);
str += '<tr><td><input type="text" id="fn'+a+'" value="'+tnarr[0]+'"></input></td><td><input type="text" id="mn'+a+'" value=""></input></td><td><input type="text" id="ln" value="'+tnarr[1]+'"></input></td><td><input type="text" id="sn'+a+'" value=""></input></td><td><input type="text" id="nn'+a+'" value=""></input></td><input type="hidden" value="'+instID+'"></input><td><input type="text" size="4" value="'+year+'"></input></td><td><input type="text" size="4" value="'+year+'"></input></td><td><input type="text" size="1" value="'+sport+'"></input></td><td><input type="text" size="1" value="'+role+'"></input></td><td></input></td><td></td><td></td></tr>';
}
str += '</table>';
$("form#phaseTwo").append(str);
}
</script>
</head><body>
<form id='AddStaffByInstitution' onsubmit='AddStaffByInstitution(); return false;'>
<table>
<tr>
<td>Institution</td><td><?php echo $ddi; ?></td>
<td rowspan=7>Name (CSV)<br/><textarea cols="50" rows="6" id="names">Lloyd Carr, Mike DeBord ,Jim Herrmann</textarea><br/>
Role<br/><?php echo $ddr; ?></td>
</tr>
<tr>
<td>Year</td><td><?php echo $ddy; ?></td></td>
</tr>
<tr>
<td>Sport</td><td><?php echo $dds; ?></td></td>
</tr>
<tr>
<td>Wins</td>
<td><input type='text' size='3' id="w" value="3"></input></td>
</tr>
<tr>
<td>Losses</td><td><input type='text' size='3' id="l" value="3"></input></td>
</tr>
<tr>
<td>Ties</td><td><input type='text' size='3' id="t" value="3"></input></td>
</tr>
<!--<tr>
<td>Overtime Ties (NHL)</td><td><input type='text' size='3' id="ot" value="3"></input></td>
</tr> -->
<tr>
<td></td><td></td><td><button type='submit'>Submit</button></td>
</tr>
</table>
</form>
<div id="action"><form id="phaseTwo" action="_process.php" method="post" onsubmit="phaseTwo(); return false;">
<input type="hidden" id="thetest" value="form139">
<br/><button type="submit">Submit</button>
</form>
</div>
<div id="add"></div>
<div id="addA"></div>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment