I've tried searching everywhere(the past 2 hours), and I've tried all these different solutions and nothing has worked for me thus far. So I thought I would come here and ask the geniuses that be. Since my Jquery isn't very good. I know it has something to do with id's and such not loaded when the script is up, but I don't know how to go about fixing this. The code I'm about to show I'm certain isn't the best. I've only been doing this for a few months. So please be patient with me.
Below is the main.php file:
echo "<div class=\"main_menu_buttons\">";
echo "<table id=\"nav\">";
echo "<tr><td>";
echo "<ul id=\"nav\">";
echo "<li><button class=\"pm_button\" onclick=\"masspm('new', 'menu')\">New</button></li>";
echo "<li><button class=\"pm_button\" onclick=\"masspm('edit', 'menu')\">Edit</button></li>";
echo "<li><button class=\"pm_button\" onclick=\"masspm('view', 'menu')\">View</button></li>";
echo "</ul>";
echo "</td></tr>";
echo "</table>";
echo "</div>";
echo "<span id=\"wait_1\" style=\"display: none;\">";
echo "<img alt=\"Please Wait\" src=\"/opserv/regimental/ajax-loader.gif\"/>";
echo "</span>";
echo "<span id=\"result_1\">";
// This is the default load screen. This will change every time we click a button.
echo "<div class=\"editor\">";
echo "<br><span class=\"header\">List of your PM groups:</span><br>";
$resultVB = $mysqliVB->query("my query");
if ($resultVB->num_rows > 0){
while ($rowVB = $resultVB->fetch_assoc()){
echo " - ".$rowVB['name']."<br>";
}
}else{
echo " - You have no groups.<br>";
}
echo "</div>";
// End of Default Load screen
echo "</span>";
-------
//Here is the script for loading ajax
<script type="text/javascript">
function masspm(type, arg, global) {
$('#wait_1').hide();
$('#wait_1').show();
$('#result_1').hide();
$.get("/forum/opserv/ajaxselect.php", {
func: type,
drop_var: arg
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
}
function finishAjax(id, response) {
$('#wait_1').hide();
$('#result_1').show();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
I used to have the validation file in this file. But was told not to put it in this file and use it in my ajax called file which is ajaxselect.php Now here is the ajaxselect.php
echo "<div class=\"editor\">";
echo "<br><span class=\"header\">Create New PM Group:</span><br>";
echo "<form name=\"new\" action=\"/forum/opserv/addon_pmgroup.php?op=addpmgroup\" method=\"post\" onSubmit=\"return validate();\">";
echo "Group Name: <input type=\"text\" name=\"name\"><br><br>";
echo "<table border=1 class=\"pmTable\"><tbody><tr>";
$i = 0;
while ($rowVB = $resultVB->fetch_assoc()){
if ($i > $rows){
echo "</td><td>";
$i = 0;
}elseif ($i == 0){
echo "<td>";
}
echo "<input type=\"checkbox\" id=\"member".$rowVB['userid']."\" name=\"members[]\" class=\"aar-checkbox\" value=\"".$rowVB['userid']."\"/><label for=\"member".$rowVB['userid']."\" class=\"aar-label\"></label> ".$rowVB['username']."<br>";
$i++;
}
echo "</tbody></table>";
echo "<br><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit\"/>";
echo "</form>";
echo "</div>";
And then here I have the validation script which is also in the ajaxselect.php
<script type="text/javascript">
function validate(){
msg = ""
if(document.new.name.value.length < 3){
msg += "Please enter a valid name
";
}
if ($("#new input:checkbox:checked").length == 0) {
msg += "Please select a member
";
}
if ($("#new input:checkbox:checked").length > 30 ) {
msg += "You many only have 30 members per group
";
}
if(msg != ""){
alert(msg);
return false;
}else{
return true;
}
}
</script>
I'm pretty sure its possible, but I'm lost as to how to make it actually validate the info. If someone would be so kind, I would appreciate any help.