Page 1 of 2
drop down button
Posted: Sat Jan 06, 2007 12:56 am
by ekosoftco
i was looking through google and didnt really see anything on this.
i was wondering if its possible, which im pretty sure it is, to have a form with a drop down button, and have different things happen according to which option is selected on the button when the form is submitted. Im thinking of having a spot where the member can edit members of his guild and choose to change their rank or delete them from the drop down button, and then hit the submit button and have it affect the database fields needed and all that good stuff.
Posted: Sat Jan 06, 2007 2:57 am
by impulse()
Try:
Code: Select all
<form name = 'choice' action = 'choice.php' method = 'post'>
<select name = 'choice'>
<option value = '1'> 1 </option>
<option value = '2'> 2 </option>
<option value = '3'> 3 </option>
</select>
</form>
Hope that helps,
Posted: Sat Jan 06, 2007 3:25 am
by Kieran Huggins
Code: Select all
<select name="action">
<option value="delete">Delete this user</option>
<option value="message">Message this user</option>
<option value="hug">Hug this user</option>
<option value="spank">Spank this user</option>
</select>
<input type="submit"/>
edit: Beat me to it

I thought I was the only one up!
Posted: Sat Jan 06, 2007 3:28 am
by impulse()
It's 9:28AM here. The day has just begun

Posted: Sat Jan 06, 2007 4:13 am
by Kieran Huggins
Posted: Sat Jan 06, 2007 4:19 pm
by ekosoftco
thanks guys

Posted: Sun Jan 07, 2007 11:20 am
by ekosoftco

sry guys, i just realized, i have 3 options, admin, recruiter, and delete. i want it to add them to admin if they chose that, recruiter if they choose that, or delete them if they choose that, how do i set that to happen when you select that certain option?
and if it helps any to see, this is my code
Code: Select all
if($_GET['action'] == 'editmember')
{
// start the table, make headers
echo '<table class="style3"><tr><th>Username</th><th>Character Name</th><th>Option</th><th>Submit</th></tr>';
// fetch results from the DB
$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error());
// print each row
while($row=mysql_fetch_assoc($result)){
echo '<tr style="background:#8ab4ff;">';
echo '<td>'.$row['Uname'].'</td>';
echo '<td>'.$row['Cname1'].'</td>';
echo '<td><FORM name=guidelinks method=post action=guildcp.php?action=actionedit>
<SELECT name="guidelinks" <OPTION SELECTED value="choose">--Choose--<OPTION value="makeadmin">Admin <OPTION value="makerecruiter">Recruiter <OPTION value="deletemember">Delete Member</SELECT>';
echo '<td><input type=submit value=Edit></td></FORM>';
echo '</tr>';
}
// close the table
echo '</table>';
}
if($_GET['action'] == 'actionedit')
{
if ($_POST['guidelinks'])
{
$result = mysql_query("UPDATE loginphp SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
}
}
Posted: Sun Jan 07, 2007 12:15 pm
by Ollie Saunders
wrap ifs around the generation of options:
Code: Select all
if ($something) $optionList.= '<option ......
Posted: Sun Jan 07, 2007 12:46 pm
by ekosoftco
i dont quite understand how to do that :/
the generation of options part i mean, not sure what you mean, sry.
Posted: Sun Jan 07, 2007 1:13 pm
by Ollie Saunders
OK right I may have misinterpreted your query. Perhaps you want to do something like this:
Code: Select all
<select onchange="this.form.submit()">
So that when a user makes a choice the form will be submitted immediately.
Posted: Sun Jan 07, 2007 1:56 pm
by impulse()
Code: Select all
if ($_POST["choice"] == "recruiter") {
echo "Recruiter";
}
else if ($_POST["choice"] == "somethingElse") {
//Do something else //
}
Posted: Sun Jan 07, 2007 2:54 pm
by ekosoftco
its not working, i always seem to be able to do the hard stuff, and get stuck on this easy stuff :/
Code: Select all
echo '<tr style="background:#8ab4ff;">';
echo '<td>'.$row['Uname'].'</td>';
echo '<td>'.$row['Cname1'].'</td>';
echo '<td><FORM name=guidelinks method=post action=guildcp.php?action=actionedit>
<SELECT name="guidelinks" ><OPTION SELECTED value="choose">--Choose--<OPTION name="admin" value="makeadmin">Admin <OPTION
name="makerecruiter" value="makerecruiter">Recruiter <OPTION name="deletemember" value="deletemember">Delete Member</SELECT>';
echo '<td><input type=submit value=Edit></td></FORM>';
echo '</tr>';
}
// close the table
echo '</table>';
}
if($_GET['action'] == 'actionedit')
{
if ($_POST["choice"] == "makeadmin")
{
$result = mysql_query("UPDATE guilds SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
}
}
it goes to the actionedit
but doesnt do anything with the selection i choose
Posted: Sun Jan 07, 2007 3:01 pm
by impulse()
You're not using $_GET, you're using $_POST.
Posted: Sun Jan 07, 2007 3:38 pm
by ekosoftco
dont i have to have something for the form to go to as well? i have btoh $_GET and $_POST in there, because when you send the button, it goes to ?action=actionedit
then in actionedit i wanted it to read the post, although, i took it out and have this
Code: Select all
if($_GET['action'] == 'editmember')
{
// start the table, make headers
echo '<table class="style3"><tr><th>Username</th><th>Character Name</th><th>Option</th></tr>';
// fetch results from the DB
$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error());
// print each row
while($row=mysql_fetch_assoc($result)){
echo '<tr style="background:#8ab4ff;">';
echo '<td>'.$row['Uname'].'</td>';
echo '<td>'.$row['Cname1'].'</td>';
echo '<td><FORM name=guidelinks method=post>
<SELECT name="guidelinks" ><OPTION SELECTED value="choose">--Choose--<OPTION name="makeadmin" value="makeadmin">Admin <OPTION name="makerecruiter" value="makerecruiter">Recruiter <OPTION name="deletemember" value="deletemember">Delete Member</SELECT>';
echo '<td><input type=submit value=Edit></td></FORM>';
echo '</tr>';
}
// close the table
echo '</table>';
}
if ($_POST["choice"] == "makeadmin")
{
$result = mysql_query("UPDATE guilds SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
}
and still it doesnt work.
Posted: Sun Jan 07, 2007 3:51 pm
by impulse()
Sorry, that was my mistake. I wasn't concentrating properly.