Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Drop Down Boxes Selecting Selected Option


i make a PHP Query select the one that has been selected in a drop down box? Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Drop Down Boxes Selecting Selected Option
I have this code to allow me to get the selected option selected in the dropdown. The option is stored in url variable the code i currently have is selecting everything. I am doing something wrong? Code:

Make Selected Option Stay Selected In A Combo After Submit
I have 3 comboboxes, one for the day, other for the month and another one for the year. Every time i select a value for the three of them and press the "Submit" button, they reset to the default option. Anyway this can be solved?

PHP And A Pre-selected Option In A Form
I've got a little text editor thing on my site, and to open a file, you input the file name and choose the folder from a drop-down list and click the Open button. The default filename is "index" and that file keeps track of all the files contained in that folder. It works okay. What's annoying is that regardless of what folder you're messing around in, the drop down list always goes back to showing the default folder name as the page is reloaded. I want it to be preselected to the folder it's in.

It seems simple enough--the folder you're in is $_GET['dir']. But I've read some HTML form how-tos, and I can only see that you can preselect using the tabindex="" or selected attribute.

Setting Selected Option Using PHP
I have a drop down list which I want to be set to what was selected when the form is submitted. As the form is processed by the same page, it returns to the preset default. How would I go about making this selection box set the option selected on the next page?

Get The Info Depending On The Selected Option
I have a page that is intendend to update a table field on DB i have a drop down menu wich displays all the position fields available on db and a text area where i will insert the new data.

now the problem: I'm using the query SELECT * FROM table WHERE position = $position
the $position is the choosen option from the drop down menu. then have echo "<textarea>$functions</textarea>" where it will show to me the present data available on DB after all this, i have another query UPDATE table SET functions = $functions WHERE position = $position

All is ok and working except the fact that he doesn't displays $functions
when selecting a option from the drop down menu?

Set The Selected Text For Option Box Of A Menu..
Having major issues with this simple task, and I cant work out why its
not doing as it should/expected.

Basically, ive got a drop down box with the added bit of php:

<select name="title" id="title">
<?php
if($_SESSION['title'] != "") {
echo '<option value="'. $_SESSION['title'] .'"
selected="selected"></option>'
}
else {
echo "<option value="" selected></option>";
}
?>

<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
</select>

Basically, if the user submits a form, the title is stored in the
session, this works fine, and then when returned to the page, the value
should be filled in.

Yet, when they return to the page, there value they selected is not
shown in this box, instead, theres just a gap. The source seems
correct, and this is whats shown:

<select name="title" id="title">
<option value="Mr" selected="selected"></option>

Keeping Select Option Value Selected
I'm trying to learn how to keep the value "selected" once a form is set to read the values and then f-write them (all within a loop). The part that's giving me a problem is the part which would return the value of the form as "selected". PHP Code:

Multiple Select Box With Selected Option ...
first of all I have three tables (tournament_game, umpire_game, umpires). Updating tournament_game umpires, each game may have from two to four umpires, and those umpires can work from one to n number of games, that's why I'm using connection table umpire_game. I'd like to get selected multiple select box of umpires in game, it could be two to four options, with all umpires listed as options example:

<select name=umpire_game[] size=10 multiple>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>

PHP Code:

How To Get Form To Remember Selected Option?
I am now trying to make a form remember which color (a select list) they selected before pressing any of the submit buttons. I entered this code into the form:

<select name="color">
<option value="red">red</option>
<option value="blue">blue</option>
</select>

The submit is a GET type. For example, if the user selects blue and then clicks on either one of the "submit" buttons, I want the form to remember/show the blue option. Right now the select list always goes back to red, the first choice. I tried doing a <?php echo $red; ?> and <?php echo $blue; ?> for the option value, but this does not work since the select list needs a value.

Select Option Stays Selected
I have a normal drop down menu:

<select name="status" class="db_list_text">
                    <option value="All" selected="selected">All</option>
                    <option value="True">Active</option>
                    <option value="False">Inactive</option>
                  </select>
The idea for this is for the user to select either true or false and then to click submit to find data that matches either one. The coding is in the same page so the form basically just reloads the page and grabbes whatever info is requested. How can I with PHP, make it that the dropdown stays on the selected option when the page is reloaded?

Best Way To Show Selected Option In List Box
I need a way so that we can show selected option in list box without using if condition in loop since some times we have lot of options and we have too much if conditions to check.

Option Selected Multiple Rows Logic
I am having problem getting the logic to work to get a multiple option box to get populated from the database and select the ones which are already in the database. Here is my code: PHP Code:

PHP/MySQL: Query Based On Selected Form Option
Using PHP and MySQL. Trying to put a list of categories into a drop down
select option of a form like:

<form name="form" action="<? print $_SERVER['PHP_SELF']?>" method="get">
<select name="subject">
<option value=""></option>
<option value="field1">Field 1</option>
<option value="field2">Field 2</option>
</select>

<input type="submit" name="Submit" />
</form>

Then I want to process it so the MySQL query gets done depending on what
was selected. I came up with this:

//connect to database
mysql_connect("$dbhost","$dbuser","$dbpass");
mysql_select_db("$dbase") or die("Unable to select database");

// Build SQL Query
if (isset($_GET['subject']))
{
switch($_GET['subject'])
{
case 'field1':
$query = "select * from tips where category = 'field1'";
break;
case 'field2':
$query = "select * from tips where text like 'field2' ";
break;
default:
echo 'No subject found'
}
}

$results=mysql_query($query);
$numrows=mysql_num_rows($results);

etc etc etc

But that switch doesn't seem to work. Anyone have a suggestion as to how
I can code this to do the MySQL query based on the subject?

Selecting Option In Select?
I am trying to populate a drop down list from values in an array, and compare a $_REQUEST or $_SESSION value to each of the array values. If they are equal, then the option in the drop down menu will be selected. Can't get it to work... Here is my code:

Selecting <option> With Preg_replace Vs Loop - Which Is Better?
and does testing merely mean running it 100 000 times and clocking it?

// using preg_replace :

$s = '
<select name="color">
<option value="">choose
<option value="red">red
<option value="green">green
<option value="blue">blue
<option value="yellow">yellow
</select>'

if($_POST)
{ $c=$_POST['color'];
$s=preg_replace('/(value="'.$c.'")/','$1 selected',$s);
}

echo $s;

// using loop :

$colors=array('red','green','blue','yellow');

echo '<select name="color">'
echo '<option value="">choose'
foreach($colors as $c){
echo '<option value="'.$c.'"'
if($_POST['color']==$c)
echo ' selected'
echo '>'.$c;
}

echo '</select>'

Php Selecting Problem - Show Selected Value When Going Back
In my pages i have a select list. For example the visitor has
5 options (including the default :D ). So here they are: the default ->
location; first option -> USA; second ->FR ; third -> IT; forth->SW

Let's call this script script1.php
In this script i want to check if there are no errors, i mean i want to see if
the visitor choose a valid location (USA, FR, IT or SW ) and not the default
one.

Now if the user select didn't select a location (equivalent to selected the
default value) the same script after is executed will will echo an error
message. If the user choose a valid location the the action will be script2.php which will echo the message: "You live in $location."

Now there is one more thing to ask. If the visitor goes back from script2.php
to script1.php i want to apper in the location field the selected option and not the default one. How is this possible?

Randomly Selecting An Element In An Array That Has Not Been Selected Before..
Im having problems in randomly selecting an element in an array that
has not been selected before.. in other words, I have an array of
answers to questions, then I want to select 5, with one of them being
the correct answer to the question, and the others not..
Here is my code.. (I already have the correct answer at array position
[0])

for($i=1;$i<=4;$i++)
{
//choose a random number in array range
$phraseArr_random_answer=rand(1,$phraseArr_size);
// check to see if random selection has not already been chosen

for($j=0;$j<=$i;$j++)
{
//check to see if element has already been chosen (j is current
array)
echo">> ".$answerArr[$j][2] ."<< >>".
$phraseArr[$phraseArr_random_answer][2]."<< <br />";
if(strcmp($answerArr[$j][2],$phraseArr[$phraseArr_random_answer][2]))
{
$alreadyUsed="FALSE";
$i--;
//document.writeln("choices[j] = " + choices[j] + " and i = " + i
// + " and viet[random_choice] = " + viet[random_choice] + "<br
/>");
//break;
echo"test";
}
else
{
$alreadyUsed="TRUE";/*
}
}
//add a random selection from phraseArr into each element of
answerArr
if ($alreadyUsed=="TRUE")
{
$answerArr[$j][2]=$phraseArr[$phraseArr_random_answer][2];
}

$answerArr[$i]=$phraseArr[$phraseArr_random_answer][2];
echo $answerArr[$i]." - ";
}

Thanks to anyone who can tell me the problem with this..

Multiple Drop Down Boxes
I want to create two multiple drop down boxes, the first will display all the company names, once this has been selected all the stock information for that company will appear in the second drop down boxes.

Form Drop Down Boxes
I have a bunch of products i want to add to a database, i have a form to submit the products to the database.

What i need to crack is to have a drop down box for category 1 (beer or wine) and then automatically populate the drop down box for category 2 depending on the first selection

if cat1 = beer then cat2 options = Lager, Malt, Stout.
if cat2 = Stout then cat3 = Guiness, london, Old boot.
if cat3 = Guiness then cat4 = Bottle, Can.

I have four sub categories so need this to work on the fly before adding all info to the database ...

Drop Down Answer Boxes
how to insert drop down answer boxes (like the oes you get in questionnaires) into my cong, i can't seem to get the coding right or make anything appear in the box.

Generating Drop Down Boxes From Mysql
i'm using php with mysql. i need to be able to extract items out of my database and put them into a drop down box so that the data is dynamic.

In this example, i need to get all of the names from the name.office field into a drop down box to be used in further scripts/processess.

<html>
<head>
</head>
<body>

<?

$db = mysql_pconnect ("localhost", "XXXX", "XXXXX");

if (!$db)

{
echo "error: could not connect to database. please try again later";
exit;
}

mysql_select_db("XXXXXXX");
$query = "select name from office";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

$row = mysql_fetch_array($result);

?>

</body>
</html>what goes here??? i have tried many things and not been able to get it to work.

Dynamic Dependent Drop Down Boxes
I need to build a dynamic page with 2 drop down boxes on it where the contents of the second drop down box are dependent upon the selection made in the first drop down box (the first box contains districts/regions and the second box contains towns/cities). The customer wants this to happen on a single screen but can this be done with PHP?

Dynamic Drop Down Boxes With Php Query
I need to build a dynamic page with 2 drop down boxes on it where the contents of the second drop down box are dependent upon the selection made in the first drop down box (the first box contains districts/regions and the second box contains towns/cities). The customer wants this to happen on a single screen but can this be done with PHP?

The above question is already answered by many people and they want me to use Javascript.
My doubt is the second box shoud query the list from a table in mysql using php. How do i do that?

Drop Down Boxes Change By Selection
what i'm trying to do is when a user selects a country say UK, all the uk states are displayed in another selection box below BUT if the US is selected all the us states are shown, this is on nion every friends/dating site just curious as to how this is done.

Dynamic Drop Down Boxes With Mysql
I'm working on a database project for a class and am having problems populating select boxes with a field from a mysql table.  The first thing that I'm trying to do is pull the field LastName from the table Faculty.  Then when the user selects the faculty member in the drop down box, it will then display all of the fields related to that faculty member...first and last name, title, office number etc and allow the user to edit those fields and then resubmit them to the database.

However I can't seem to get the drop down box to populate, so if anyone has any suggestions as to how to fix this I would love to hear them. Code:

Filtering Selection In Multiple Drop Down Boxes
I want to allow a user to conduct a search on a database using multiple drop down boxes.
On the first page they will have a drop box filled with records from field A. Once they select which one they want, a second drop down box will then appear with records from field B which are present for field A (a filter).

What I want though is that the first dwon down box still appears on the second page, but shows the record that the user selected. What is happening now is that when the second page comes up, the first box shows the default selection rather than the selection that the user chose. My code for the drop down boxes is: PHP Code:

Showing What Was Selected In Drop-down Menu
I'm trying to create a form where the user inputs data, i validate it with php, and if some of the input is missing or invalid then i print out errors with the form filled out with the information they entered/selected previously so they can change/add to it.

The problem I'm having is setting my drop down menus to be selected when the form is returned instead of returning their original state. The menu I have is named A ($A). Here's an example of what I'm doing that isn't working: PHP Code:

Using Variables To Control What Is Selected In An Drop-down Menu?
I have a drop-down menu with the states. I don't necessarily want to have the menu dynamic with a database, but I want to be able to control what is selected using a variable. Code:

<select name=state id=state>
<option value="" selected>--</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
etc...
</select>

Selecting From A Drop Down Box
I have a drop down box populated with names of towns from my db (MySQL) all that is working fine. My problem is I do not know how I select a town in the box and have it take me to that web page on my site.

Select <option> </option>
I have this script in a form, it is trying to send a selection from the from to the next page. But the proble is that if the selection has a space in it, it only sends the first work to the next page. Code:

Multiple Selected="selected" In A List.
I have a database with 1 to many and the many is a list with multiple
selects in a list. When I click on a master record I have as part of
my form the select statement for the multiple choice list. I want the
list to highlight the multiple chosen values. here is part of the
code.

$dresscat = specdresscat($dresstypeid); //this is the query to get the
values in the detail table
$drcatrow = pg_fetch_array($dresscat);// the array for the detail
table.
<select name="stages[]" multiple="multiple">
<?php
$allstages = allstages(); // this is a function to query my database
to get the value for the list.
while ($allstagerows=pg_fetch_array($allstages)) {
$eachstage= $allstagerows["stageid"];
$specstage= $drcatrow["stageid"]; // this is the point I need help
if ($specstage == $eachstage){ ?>
<option value=<?php echo $eachstage;?> selected="selected"><?php echo
allstagerows["stage"]?></option>
<?php }else{ ?>
<option value=<?php echo $eachstage;?>><?php echo
$allstagerows["stage"]?></option>
<?php
}
}
?>
</select>

Drop Down Lists Changing Depending On Other Drop Downs
I want to have a drop down system like this one.  But without the radio buttons.

I want to have 3 drop downs but have no idea how to go about it.  I assume I will need to activate some sort of Javascript on the onChange event of the option drop downs.

Check Boxes
I have a very little problem with check boxes. How can I write a simple PHP code to tell me when a check box has been checked, and then use the name of the checkbox in a function.

Reading POP Boxes
I've been looking round for something that will read the contents of a pop
box and populate a MySQL table.

The e-mails will all be of a fixed format and include a jpeg as an
attachment. I need to put the following columns in:

sender
subject
body
filename (possibly appended to the date to mitigate the risk of
The script would also need to save the attachment to a predetermined folder.

Does anyone know of anything that would do this? Alternatively, how much
would it cost for someone to get this working for me?

Alert Boxes
do u know the alert box in javascript?

when u write alert("somthing");

well i need that in php what is the alternative function for that in php?

Combo Boxes Question
I am wondering how I can make the whole array appear in the code that is below with the database entry to be selected. At the moment it just displays the database entry.

Populating Two Combo Boxes
I have one combo box (Category) which is populated by a MySQL table using php. I am trying to use the onchange javascript to submit the value selected so that I can populate the other combo box (sub-category) based on what was previously choosen. So can anybody give me a clue on how to submit the first boxes value so that the second can see what was selected (javascript function).

An Array Of Text Boxes
I have the full code in a php script where I essentially display a form with checkboxes, and 2 text boxes associated with each checkbox to record grades ( marks and remarks ). The form displays correctly and the checkboxes I select do pass the correct id numbers for the students to be graded, also the numeric data in the first textbox is correctly transmitted HOWEVER the data in the second textbox gets randomly truncated.

e.g, if the "remarks" textbox has 'hello', it gets truncated to 'o'. It seems I'm not resetting something or there is another simple oversight somewhere, perhaps the script treating the data as a string rather than as an array Code:

Dynamic Combo Boxes
i have a problem with creating some dynamic combo boxes. i have a form and the user enters the number of printers required, on the recieving page i display that many combo boxes ready for their input...but the problem is its not generating the correct number of combo boxes for some reason. i think i'ts because i need to reset the cursor on the result set so it can whip through the printers again but am not sure. please see following code:

Printing Colored Css-boxes
I've got a page with a couple of tables inside a couple of colored boxes(css-style), but when I try to print the page I end up with a copy without colors.

Conditional List Boxes
I am attempting to create a list box that is dynamically populated based on the selection of another list box.  I am in way over my head..only way to learn I guess.  The code below has a year listbox and then based on the year selection, the page should either show another listbox (show industry selection when year <> 2005) or it should render the main form (when year=2005). I cannot get the main form to appear. Code:

If Statement And Check Boxes.
I have a database full of different articles/stories. I would like to have a publish check box so that if it is checked, that story appears on the homepage, I know how to do this. HOWEVER, i need ot be able to limit this so that only one can ever be checked off... Code:

Dynamic Text Boxes
I have a form where field techs can close out service calls, Time in, time out, work done, who the tech is....ect...

Currently I have 20 fields for parts..... Part1 / Part1QTY....and so on to Part10 / Part10QTY.... the form emails, and it also feeds data into MySQL... so everything is working fine...

What I would like to do, is stream line it...so there is only 2 fields...part_number and qty....and when techs needs to enter more parts then click on a button that creates 2 new sets of text boxes for input....
thus allowing me to have them enter more the just 10 parts and qty's.

I thought about, maybe having a secondary form on my HTML page, with different sets of submit buttons, and they can enter 1 part at a time... but I could not get the secondary form Submit button to not clear the data in the primary form...so that didn't work for me.! I'm am basically stuck here... there maybe one or two other issues I have...but those are not so critical.

I do have a great deal of MS Access experience but this PHP is a totally different monster. For those who know access, it's very easy to add a new record in a subform and just keep adding records...which is sort of what I'm trying to do here.

Dynamic Listy Boxes
we are trying to  buid some dynamic list boxes.  Our  code that  generates the
listbox  creates  a string  containing the list box definition and the  last line of the  file is echo  $outstr. 

When we  execute this, the list box works fine. Now when we embed it into am html page  in this way: <?php  include statuslistbox.php   ?>, we get  errors  that  say "constant  statuslistbox.php  not defined"  The listbox define file has  the php brackets  top and bottom. The embeding html has no brackets other than the ones show above. It seems to make no difference  if the calling file  is a php extension html extension.

Spaces In <input Text> Boxes.
When I submit a form where a user has typed a space into the input box, then check that value in the action .php file, only the text before the first space is displayed. How can I get all of the text sent?

eg

Code:
<form name="form2" method="post" action="temp.php">
<input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</form>

Then in temp.php
Code:
echo "Username = $name";

If the user enters "Greg Bennet" into the text field, I get back "Username = Greg".

Dynamic Text Boxes With While Loop?
Basically I have a dynamic number of categories. Each of these categories requires a text box, therefore I have a dynamic number of text boxes. My question is if there is anyway using a while loop that this can be done?

<?
while ($nextcat = array.php($categories))
{
echo $nextcat;
$varname = $strip_tags($nextcat)
?>
<input type = textarea name = <? $varname ?>>
<? } ?>

Dynamically Filling Selection Boxes
I was wondering if anyone knows how to fill a selection box with different values depending on a selection made in a nother selection box in the same page. I dont know if what I'm tryin to do can be done or not, at least in PHP. First a quick background:

We have a number of projects running right now, each of which is subdevided into various tasks. Now, I've got two selection boxes. The first contains a list of all current projects. What I want to do is this: when someon selects a project from the first box, I'd like the second box to be filled with a list of the tasks that have been assigned tot hat project.

Using Mail() And Avoiding Spam Boxes !
Im using the mail() command to send an email to people who register on
my site, but many are ending up in people's spam boxes on hotmail.

This problem isn't true of all users - probably around 60%.

Im being as open as possible using a number of headers, but can anyone
suggest a way of getting through with less problems ?

$sender = "From: Name <email@domain.com>" . "";
$sender .= "Return-Path: email@domain.com" . "";
$sender .= "MIME-Version: 1.0" . "";
$sender .= "Content-Type: text/plain; charset=iso-8859-1" . "";
$sender .= "Content-Transfer-Encoding: 8bit" . "";
$sender .= "X-Mailer: PHP/" . phpversion();

Passing Values From Text Boxes
what I'm trying to do is pass some values from text boxes, yes it may sound simple, but let me explain more... I've got a form, and what I want to do is that when you enter a new question and select a existing category from the drop down box, it then inserts the values into the database no problem. However if enter a new question, and a new category, then submit the info, I get a null value. The Code...


Copyright © 2005-08 www.BigResource.com, All rights reserved