Jump to content

[SOLVED] Drop Down Box Other


Ell20

Recommended Posts

Hey,

 

Im trying to create a drop down box which at the end has a Other option.

If Other is selected I want the variable which is set from the drop down box to be set to whatever is typed in, in the input box below by the user e.g:

 

<select name="team_name"><option value='' selected disabled>Select Team Name</option>
<option value="1st XI">1st XI</option>
<option value="2nd XI">2nd XI</option>
<option value="3rd XI">3rd XI</option>
<option value="Other>Other</option>
</select>

 

I dont really want to use Java or AJAX, is there anyway in which this can still be done?

 

Cheers

Link to comment
Share on other sites

Having a bit of trouble, I can only get either Other to work or a selected value from the drop down box to work, here is my code:

 

if (isset($_POST['submit2'])) {

if($_POST['team_name'] == 'Other') {
$team_name = $_POST['textboxother'];

} else {

$team_name = escape_data($_POST['team_name']);
$captain = escape_data($_POST['captain']);
$vice_captain = escape_data($_POST['vice_captain']);
$description = escape_data($_POST['description']);

$query = "INSERT INTO cricket_teams (club_id, team_name, captain, vice_captain, description) VALUES ('$id', '$team_name', '$captain', '$vice_captain', '$description')";
$result = @mysql_query ($query);
if ($result) {
echo '<h3>New Team Created!</h3>';
}
}
}

 

Cheers

Link to comment
Share on other sites

I think what you are trying to do is add the value of the text box to the drop down box. I.E populating a drop down list more than once. If this is correct. Where is the drop down getting ints info freom. Is it a database field? If so you will have to create a SQL script to add this to the databes.

 

Desmond.

 

Link to comment
Share on other sites

No i dont think your quiet along the right lines.

 

All I want is a drop down box with the option "Other" at the bottom.

 

If the option "Other" is selected from the drop down box then whatever is written in the text box below becomes the value of the drop down box.

 

e.g

Drop down box:

Egg

Milk

Other (selected)

 

Text box: Sasuage

 

I now want sausage to be put into the database instead of Other etc.

Link to comment
Share on other sites

Yes I see but Why select Other from the drop down box and then type Sasuage in the text box as well. You should be able to detect if the text box is empty. I.E. leave the drop down box alone with it's default. Lets say it defaults to the first Item Egg. Because you typed in Sasuage into the text box. When you hit submit. The next form will add Sasuage to the database regardless of what was selected in the drop down box.

 

I am asuming that the drop down box has 2 items in a table Egg and Milk. And these values are used in the drop down box, AND that you do not want Sasuage to be added to the database for future use in the drop down box.

 

Is this correct

 

Demond.

 

Link to comment
Share on other sites

I want Other to be selected in the drop down box to make things easier for the user. If Egg is selected then sausage is typed in then it makes it confusing.

 

I do not want sausage to be added to the drop down box for future use.

 

I can get either the Other then text box option to work OR the normal selection from the drop down box however I cant get them to work together.

 

<?php
if (isset($_POST['submit2'])) {

$team_name = escape_data($_POST['team_name']);
$captain = escape_data($_POST['captain']);
$vice_captain = escape_data($_POST['vice_captain']);
$description = escape_data($_POST['description']);

if($_POST['team_name'] == 'Other') {
$team_name = $_POST['textboxother'];

$query = "INSERT INTO cricket_teams (club_id, team_name, captain, vice_captain, description) VALUES ('$id', '$team_name', '$captain', '$vice_captain', '$description')";
$result = @mysql_query ($query);
if ($result) {
echo '<h3>New Team Created!</h3>';
}
}
}
?>

Link to comment
Share on other sites

Done it  ;D

 

I was just closing the if statement in the wrong place:

 

<?php
if (isset($_POST['submit2'])) {

$team_name = escape_data($_POST['team_name']);
$captain = escape_data($_POST['captain']);
$vice_captain = escape_data($_POST['vice_captain']);
$description = escape_data($_POST['description']);

if($_POST['team_name'] == 'Other') {
$team_name = $_POST['textboxother'];
}

$query = "INSERT INTO cricket_teams (club_id, team_name, captain, vice_captain, description) VALUES ('$id', '$team_name', '$captain', '$vice_captain', '$description')";
$result = @mysql_query ($query);
if ($result) {
echo '<h3>New Team Created!</h3>';
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.