473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to select item in dropdown after posting a form?

27 New Member
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($_SESSI ON[nuser]);
}
print <<<PAGE
<div>
<form name="userForm" action="users.p hp" method="post">
<fieldset>
<legend>Add User</legend>
<p>
<label for="name">*Use r 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">Ac cess 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">Admin istrator</option>
</select>
</p>
<p>
<input type="submit" name="aSubmit" value="Submit" onclick="if (userCheck() == false) return false;"/>
<input type="reset" />
<input type="button" onclick="locati on.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 2188
jodan
1 New Member
//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">Admin istrator</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'=>'Adm inistrator', '2'=>'Read Only Access');

echo '<select id="access" name="access">' ;
foreach($option s_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
bdbeames
27 New Member
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
9621
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 select more. Also how can these choices be saved somehow so tha when the user goes to the next page the choices he made can be written to the database. For example The choices in the dropdown may be
1
10165
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 closes. The closing of the dropdown list can happen without changing the dropdown, hence the onchange event is not a sure way to determine that the dropdown list closed. Is this possible in Internet Explorer?
2
6440
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 between "display='none'" and "display=''". However the problem is that - in Internet Explorer 6 the dropdown (<select>...) always hides the menu
6
3468
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 want to be able to select an item on the dropdown list based on the value of the javascript variable. Let's say this is my list and my variable: <select id='popup'>
7
2057
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 close, but I feel that I'm getting there. Thanks in advance for any help. I much appreciate it. -pk <SCRIPT>
1
2138
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 listcount of a dropdown element is 1 how do I capture the value of this element and set the dropdown box to show/select this one element? (instead of showing empty)
7
4222
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 the first item in the dropdown is always displayed. Template Code: <asp:TemplateColumn HeaderText="DropDown"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval
1
24387
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 width will be necessary. How do I tell the dropdown (<SELECT>) and/or column (<TD>) to automatically size itself to the greater of widest item in the dropdown, and then get the smaller dropdowns to fill the width of the column? If I specify in...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.