drop down button
Moderator: General Moderators
drop down button
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.
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.
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Try:
Hope that helps,
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>
Code: Select all
echo $_POST["choice"];- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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());
}
}- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
wrap ifs around the generation of options:
Code: Select all
if ($something) $optionList.= '<option ......- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
OK right I may have misinterpreted your query. Perhaps you want to do something like this:So that when a user makes a choice the form will be submitted immediately.
Code: Select all
<select onchange="this.form.submit()">-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Code: Select all
if ($_POST["choice"] == "recruiter") {
echo "Recruiter";
}
else if ($_POST["choice"] == "somethingElse") {
//Do something else //
}its not working, i always seem to be able to do the hard stuff, and get stuck on this easy stuff :/
it goes to the actionedit
but doesnt do anything with the selection i choose
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());
}
}but doesnt do anything with the selection i choose
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
and still it doesnt work.
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());
}