Jump to content

[SOLVED] Passing Submitted Value To UL


Xtremer360

Recommended Posts

I have some JS and a executeform function check it out. What I want to happen is once the user selects a character name from the drop down and clicks Add then it is placed in a UL which is below it which right now says "This handler does not have any characters assigned."

 

function newhandler() {
if (isset ($_POST['submit'])) { // Handle the form.
   
   // Define the query.
   $salt = "rweweroiu23i4u89wu89fu9sadhfiuhaw89eriuahdfuiwher";
   $password = md5(md5(md5(encrypt(md5(md5($password.$salt))))));
   $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) VALUES ('$login', '$p','$surname','$firstname', '$email', '$aim', '$msn', '$forumid', '$account', '$admin')";

   // 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();

}
print'<h1 class="backstage">Handler Management</h1><br />';
print'<h2 class="backstage">Add New Handler Account</h2><br />';
print'<form name="newhandler" action="backstage.php" method="post" >';
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">';
print'<option value="1">Enabled</option><option value="2">Disabled</option>';
print'</select></td>';
print'</tr>';
print'<tr>';
print'<td class="rowheading">Administrator:</td>';
print'<td class="row3"><select name="admin" class="selection">';
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="submit"></form><br />';
print'<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br />';
print'<form method="POST" name="handlermodule">';
print'<input type="hidden" name="action" value="handler">';
print'<input type="hidden" name="routine" value="0">';
print'<input type="hidden" name="id" value="0">';
print'<input type="hidden" name="characterid" value="0">';
print'<input type="hidden" name="option" value="0">';
print'</form>';
print'<script type="text/javascript" language="javascript">
function executeformhandler(routine,id,characterid,option) {
document.handlermodule.routine.value = routine;
document.handlermodule.id.value = id;
document.handlermodule.characterid.value = characterid;
document.handlermodule.option.value = option;
document.handlermodule.submit();
}
</script>';
print'<h2 class="backstage">Characters<br /><br /><form method=post><input type=hidden name=action value=handler><input type=hidden name=routine value=addcharacter><input type=hidden name=option value=0><input type=hidden name=id value="0"><select name="characterid" class="dropdown">';
print'<option value="0">- 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="submit" value="Add" class="button" ></form></h2><br />';
print'<ul></ul>';
print'This handler does not have any characters assigned.<br /><br />';
print'<h2 class="backstage"><form method="POST"><input type="hidden" name="action" value="mainmenu"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
} 

 

Link to comment
Share on other sites

example of how to do this:

 

<script type="text/javascript">
function createListItem(newItem)
{
if (newItem)
document.getElementById("mylist").innerHTML += "<li>" + newItem + "</li>";
}
</script>

<select onchange="createListItem(this.value)">
<option selected value="">Pick An Item
<option value="Item 1">Item 1
<option value="Item 2">Item 2
<option value="Item 3">Item 3
</select>

<br><br>

<ul id="mylist"></ul>

Link to comment
Share on other sites

Updated Code. Still not doing anything.

 

function newhandler() {
if (isset ($_POST['submit'])) { // Handle the form.

// Define the query.
$salt = "rweweroiu23i4u89wu89fu9sadhfiuhaw89eriuahdfuiwher";
$password = md5(md5(md5(encrypt(md5(md5($password.$salt))))));
$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) VALUES ('$login', '$p','$surname','$firstname', '$email', '$aim', '$msn', '$forumid', '$account', '$admin')";

// 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(); 

} 
print'<h1 class="backstage">Handler Management</h1><br />';
print'<h2 class="backstage">Add New Handler Account</h2><br />';
print'<form name="newhandler" action="backstage.php" method="post" >';
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">';
print'<option value="1">Enabled</option><option value="2">Disabled</option>';
print'</select></td>';
print'</tr>';
print'<tr>';
print'<td class="rowheading">Administrator:</td>';
print'<td class="row3"><select name="admin" class="selection">';
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="submit"></form><br />';
print'<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br />
<script type="text/javascript">
function WrestlerList(addWrestler)
{
if (addWrestler)
document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>";
return WrestlerList;
}
</script>';
print'<h2 class="backstage">Characters<br /><br />';
print'<form method=post id="form1" name="addwrestler" onsubmit="return WrestlerList(this);"><select name="characterid" class="dropdown" onchange="WrestlerList(this.value)">';
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 name="submit" type="submit" value="Add" class="button"></form></h2><br />';
print'<ul id="characterlist"></ul>';
print'This handler does not have any characters assigned.<br /><br />';
print'<h2 class="backstage"><form method="POST"><input type="hidden" name="action" value="mainmenu"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
}

Link to comment
Share on other sites

When I click Add it plays a new LI in the UL however instead of the value it places this: [object HTMLFormElement]

 

How do I a)Get it to display value which would be the character's name and b)when there isn't one selected yet have it then show "This handler does not have any characters assigned."

 

Code from ajax page:

function WrestlerList(addWrestler)
{
if (addWrestler)
document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>";
return WrestlerList;
}

 

PHP Page:

print'<script type="text/javascript" src="ajax.js"></script>';
print'<h2 class="backstage">Characters<br /><br />';
print'<form method=post name="addwrestler" onsubmit="return WrestlerList(this);"><select name="characterid" class="dropdown">';
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 name="submit" type="submit" value="Add" class="button"></form></h2><br />';
print'<ul id="characterlist"></ul>';
print'This handler does not have any characters assigned.<br /><br />'

Link to comment
Share on other sites

first off, you really don't need an onsubmit or even a submit button; if you are not submitting any data. i would just add the function to a button and if you are going to call it this way; you would need to do something along the lines of this:

 

function WrestlerList()
{
var addWrestler = document.addwrestler.characterid.value;
if (addWrestler)
document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>";
return WrestlerList;
}

Link to comment
Share on other sites

function WrestlerList()
{
var addWrestler = document.addwrestler.characterid.value;
if (addWrestler) {
document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>";
return WrestlerList;
}
else {
document.getElementById("characterlist").innerHTML += "<li>This handler does not have any characters assigned.</li>";
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.