Xtremer360 Posted January 22, 2009 Share Posted January 22, 2009 Nothing happens when the button is clicked to add a new character name to the UL. This is in my ajax.js function WrestlerList() { var addWrestler = document.getElementById("character_selection").value if (addWrestler) { // Here we append a new wrestler to your hidden field using a comma document.getElementById("chars").value += addWrestler+","; // Continue your original functionality document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>"; return WrestlerList; } } backstagefunctions.php print '<script type="text/javascript" src="ajax.js"></script>'; print '<h2 class="backstage">Characters<br /><br />'; print '<select name="characterid" class="dropdown" id="character_selection">'; print '<option value="">- Select -</option>'; $query = 'SELECT charactername FROM characters'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r"; } print '</select> <input type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />'; print '<ul id="characterlist"></ul><br /></form>'; Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Can someone help me out here? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 works for me: <script> function WrestlerList() { var addWrestler = document.getElementById("character_selection").value if (addWrestler) { // Here we append a new wrestler to your hidden field using a comma document.getElementById("chars").value += addWrestler+","; // Continue your original functionality document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>"; return WrestlerList; } } </script> <?php // print '<script type="text/javascript" src="ajax.js"></script>'; print '<h2 class="backstage">Characters<br /><br />'; print '<select name="characterid" class="dropdown" id="character_selection">'; print '<option value="">- Select -</option>'; // $query = 'SELECT charactername FROM characters'; // $result = mysql_query ( $query ); // while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"Foobar1\">Foobar1</option>\r"; print "<option value=\"Foobar2\">Foobar2</option>\r"; print "<option value=\"Foobar3\">Foobar3</option>\r"; print "<option value=\"Foobar4\">Foobar4</option>\r"; // } print '</select> <input type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />'; print '<ul id="characterlist"></ul><br /></form>'; ?> Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Its supposed to send the selected value from the dropdown menu as a new LI to the UL called character list and its not doing it for me Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 what is the complete code then? load the page up, do a view source, and copy paste that here. also, are you getting any JavaScript errors? what OS/Browser are you using? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 function addhandler() { print '<h1 class="backstage">Handler Management</h1><br />'; print '<h2 class="backstage">Add New Handler Account</h2><br />'; print '<form name="addhandler" method="post" action="backstage.php" id="addhandler">'; print '<table width="100%" class="table2">'; print '<tr>'; print '<td width="120" class="rowheading">Username:</td><td class="row3"><input type="text" name="login" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Password:</td><td class="row3"><input type="password" name="password" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Surname:</td><td class="row3">'; print '<input type="text" name="surname" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Firstname:</td>'; print '<td class="row3"><input type="text" name="firstname" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Email:</td>'; print '<td class="row3"><input type="text" name="email" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">AIM:</td>'; print '<td class="row3"><input type="text" name="aim" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">MSN:</td>'; print '<td class="row3"><input type="text" name="msn" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Forum ID:</td>'; print '<td class="row3"><input type="text" name="forumid" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Account:</td>'; print '<td class="row3"><select name="account" class="selection"><option value="0">- Select -</option>'; print '<option value="Active">Active</option><option value="Inactive">Inactive</option>'; print '</select></td>'; print '</tr>'; print '<tr>'; print '<td class="rowheading">Administrator:</td>'; print '<td class="row3"><select name="admin" class="selection"><option value="0">- Select -</option>'; print '<option value="2">No</option><option value="1">Yes</option>'; print '</select></td>'; print '</tr>'; print '</table><br />'; print '<input type="submit" value="Save Handler" class="button" name="addhandler"><br />'; print '<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br /><br />'; print '<script type="text/javascript" src="ajax.js"></script>'; print '<h2 class="backstage">Characters<br /><br />'; print '<select name="characterid" class="dropdown" id="character_selection">'; print '<option value="">- Select -</option>'; $query = 'SELECT charactername FROM characters'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r"; } print '</select> <input type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />'; print '<ul id="characterlist"></ul><br /></form>'; print '<h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>'; } var loadedobjects="" var rootdomain="http://"+window.location.hostname function ajaxpage(url, containerid) { url = 'backstagefunctions.php?f=' + url; var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject) { // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { } } } else { return false } page_request.onreadystatechange=function() { loadpage(page_request, containerid) } page_request.open('GET', url, true) page_request.send(null) } function loadpage(page_request, containerid) { if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs() { if (!document.getElementById) return for (i=0; i<arguments.length; i++) { var file=arguments[i] var fileref="" if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1) { //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1) { //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!="") { document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } function WrestlerList() { var addWrestler = document.getElementById("character_selection").value if (addWrestler) { // Here we append a new wrestler to your hidden field using a comma document.getElementById("chars").value += addWrestler+","; // Continue your original functionality document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>"; return WrestlerList; } } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 for the page, please post the GENERATED code. again, do view source in your browser. you php does dynamic steps that i can't reproduce. all i can do is assume what it does. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 <h1 class="backstage">Handler Management</h1><br /><h2 class="backstage">Add New Handler Account</h2 ><br /><form name="addhandler" method="post" action="backstage.php" id="addhandler"><table width="100 %" class="table2"><tr><td width="120" class="rowheading">Username:</td><td class="row3"><input type="text" name="login" class="fieldtext490"></td></tr><tr><td class="rowheading">Password:</td><td class="row3" ><input type="password" name="password" class="fieldtext490"></td></tr><tr><td class="rowheading">Surname :</td><td class="row3"><input type="text" name="surname" class="fieldtext490"></td></tr><tr><td class ="rowheading">Firstname:</td><td class="row3"><input type="text" name="firstname" class="fieldtext490" ></td></tr><tr><td class="rowheading">Email:</td><td class="row3"><input type="text" name="email" class ="fieldtext490"></td></tr><tr><td class="rowheading">AIM:</td><td class="row3"><input type="text" name ="aim" class="fieldtext490"></td></tr><tr><td class="rowheading">MSN:</td><td class="row3"><input type ="text" name="msn" class="fieldtext490"></td></tr><tr><td class="rowheading">Forum ID:</td><td class ="row3"><input type="text" name="forumid" class="fieldtext490"></td></tr><tr><td class="rowheading">Account :</td><td class="row3"><select name="account" class="selection"><option value="0">- Select -</option ><option value="Active">Active</option><option value="Inactive">Inactive</option></select></td></tr> <tr><td class="rowheading">Administrator:</td><td class="row3"><select name="admin" class="selection" ><option value="0">- Select -</option><option value="2">No</option><option value="1">Yes</option></select ></td></tr></table><br /><input type="submit" value="Save Handler" class="button" name="addhandler"> <br /><input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br /><br /><script type="text/javascript" src="ajax.js"></script><h2 class ="backstage">Characters<br /><br /><select name="characterid" class="dropdown" id="character_selection" ><option value="">- Select -</option><option value="Anguish">Anguish</option> <option value="Pyro">Pyro</option> </select> <input type="hidden" id="chars" name="chars" value=""><input type="button" value ="Add" onclick="WrestlerList()" class="button"></h2><br /><ul id="characterlist"></ul><br /></form><h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200" ></form></h2> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 all works perfectly in FF3, what OS & Browser are you using? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 XP and FF3 Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Wow that's weird I tried it in my IE browser and it worked fine. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 was just about to say, test it in IE. it's probably one of your FF plugins. load FF up in Safe Mode and test it Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Okay so I ran a test on my form to have it go into the DB and this came up: Could not add the entry because: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'Anguish,')' at line 1". The query was INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('Testing', 'klad;jf', 'l;jdafl;','kljl;kj', 'k;lj', 'k', ';ljk', ';l', 'Active', '2',, 'Anguish,'). //Form was submitted - determine the form if ( isset ( $_POST['edithandler'] ) ) { // Define the query. $password = md5($p); // Currently $p does not have a value $login = $_POST['login']; $p = $_POST['password']; $surname = $_POST['surname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $aim = $_POST['aim']; $msn = $_POST['msn']; $forumid = $_POST['forumid']; $account = $_POST['account']; $admin = $_POST['admin']; $query = "UPDATE INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."')"; // Execute the query. if (@mysql_query ( $query )) { print '<p>The handler has been edited.</p>'; } else { print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>'; } //mysql_close (); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 that isn't the same query...you posted an UPDATE, and the error is in an INSERT Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 oops wrong one sorry //Form was submitted - determine the form if ( isset ( $_POST['addhandler'] ) ) { // Define the query. $password = md5($p); // Currently $p does not have a value $login = $_POST['login']; $p = $_POST['password']; $surname = $_POST['surname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $aim = $_POST['aim']; $msn = $_POST['msn']; $forumid = $_POST['forumid']; $account = $_POST['account']; $admin = $_POST['admin']; $query = "INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."',, '".addslashes($_POST['chars'])."')"; // Execute the query. if (@mysql_query ( $query )) { print '<p>The handler has been added.</p>'; } else { print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>'; } //mysql_close (); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 here is an extra comma before the last value: $query = "INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."', '".addslashes($_POST['chars'])."')"; Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Okay it works great however I want it to fill all the values and not have a trailing comma after the last one and its lost it's ability of a sudden to md5 the password field is that because i"m in safemode Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 you are not getting the md5() value because you assign $p AFTER the md5()...change the order around: //Form was submitted - determine the form if ( isset ( $_POST['addhandler'] ) ) { // Define the query. $login = $_POST['login']; $p = md5($_POST['password']); // $password = md5($p); //This isn't needed any more $surname = $_POST['surname']; $firstname = $_POST['firstname']; $email = $_POST['email']; ... and what SHOULD the field for 'characters' look like then? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 What do you mean? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 should it be: Anguish,Pyro Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Well basically it should fill all the values that were put into the UL into the DB until all the values have been filled then there should NOT be an ending comma. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 //Form was submitted - determine the form if ( isset ( $_POST['addhandler'] ) ) { // Define the query. $login = $_POST['login']; $p = md5($_POST['password']); $surname = $_POST['surname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $aim = $_POST['aim']; $msn = $_POST['msn']; $forumid = $_POST['forumid']; $account = $_POST['account']; $admin = $_POST['admin']; $characters = preg_replace('/,$/','',$_POST['chars']); $query = "INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."',, '".addslashes($characters)."')"; Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Great. Thank you very much however can you explain that line of code so I can understand it please. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 $_POST['chars'] is a string, with the characters in it. the line of code just removes the last comma if there is one Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.