473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to select item in dropdown after posting a form?

Ok, It has been one of those days. Here is my bump in the road.
I have an add user form for the administrator. The administrator enters name, password and then selects access level from a dropdown. When the data is posted I take the administrator to a page where all users can be viewed. I then allow the administrator to select a user in the list that they would like to edit. The administrator is taken back to the add user form, but the form is filled in with the data of the user they wish to edit.

Problem..
My access level selection in a dropdown list. When the administrator wants to edit a user and the data is filled in the form, I can not figure out how to select the correct option from the dropdown. Any help will be nice.

[php]
function useradd() {
if ($_GET[option] == "edit") {
$nuser = getUser($_SESSION[nuser]);
}
print <<<PAGE
<div>
<form name="userForm" action="users.php" method="post">
<fieldset>
<legend>Add User</legend>
<p>
<label for="name">*User Name</label><input type="text" id="name" name="name" value="$nuser[name]" />
</p>
<p>
<label for="password">*Password</label><input type="password" id="password" name="password" value="" />
</p>
<p>
<label for="access">Access Level</label>
//This is where I need help selecting read only or administrator
<select id="access" name="access">
<option value="2">Read Only Access</option>
<option value="1">Administrator</option>
</select>
</p>
<p>
<input type="submit" name="aSubmit" value="Submit" onclick="if (userCheck() == false) return false;"/>
<input type="reset" />
<input type="button" onclick="location.href='users.php'" value="Back" />
</p>
</fieldset>
</form>
</div>
PAGE;
}
[/php]

The $nuser array will contain name, password, and accesslevel.

Thanks
Nov 20 '07 #1
2 2156
jodan
1
//This is where I need help selecting read only or administrator
<select id="access" name="access">
<option value="2">Read Only Access</option>
<option value="1">Administrator</option>
</select>
Two options:

1.
Expand|Select|Wrap|Line Numbers
  1. //change your select to this:
  2.  
  3.                <select id="access" name="access">
  4.                      <option value="2"<?php if($nuser['accesslevel']=="2") echo " selected";?>>Read Only Access</option>
  5.                      <option value="1"<?php if($nuser['accesslevel']=="1") echo " selected";?>>Administrator</option>
  6.                </select>
2.
[PHP]<?php

$options_array = array('1'=>'Administrator', '2'=>'Read Only Access');

echo '<select id="access" name="access">';
foreach($options_array as $value=>$option){
echo '<option value="'.$value.'"';
if($nuser['accesslevel'] == $value){
echo " selected";
}
echo '>'.$option."</option>\n";
}
echo '</select>';

?>[/PHP]

Hope this helps. Cheers.
Nov 20 '07 #2
Thanks for the help.

I like you second option.
Nov 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to...
1
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list...
2
by: Joachim Bauer | last post by:
I'm using the code below to display a menu that opens when the mouse goes over the main menu item (try it in your browser to understand the behaviour). It uses "position:absolute" and a switch...
6
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I...
7
by: pk | last post by:
Here is my code, and it's not working. Please help me get through this. I've read every single tutorial and you may even see remnants of some of their variables in my code. I don't know if I'm...
1
by: seansan | last post by:
Hi, I ahve an issue that I could tackle myself. sometimes a dropdown box is filled with only one element. How can I set this dropdown box to auto-select this one option? So in VB. If my...
7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
1
by: RichardR | last post by:
I have a webpage which has a table that contains a column with several drop down boxes (<SELECT>). The contents of the drop down boxes are dynamically populated so I have no idea what the actually...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.