Jump to content

dropdown with text input


jasontallon

Recommended Posts

Hi

 

Any help appreciated.

 

I am new to PHP & MYSQL,

 

I am looking for the following code or advice as to where i could find info re creating same.

 

A drop down menu and input box where when the user selects an option and enters a number in a text area the value is sent to a DB table/field.

 

Example:

 

Drop down menu with 5 options - phone 1, phone 2, etc when user selects phone 2 they then enter a number in an input box and hits submit the number posts to the phone2 field in the table, or user selects phone 3 enters a number in a text field and the number is posted to the phone3 field in the database table.

 

Thanks for any help

 

Jason

Link to comment
Share on other sites

or if the the user will be using it you can have them input their username so when they select the phone/number it's saved to their "profile" or database row.. whatever you want to call it. I've updated haku's version if it suites your needs:

 

 

 

<?PHP
$username = $_POST['username'];
$number = $_POST['drop_down_menu'];
$phone = $_POST['phone_number'];
$query = "UPDATE phone_numbers SET phone_number{$number}='{$phone}' WHERE users='$username'";
?>

I think thats how it would go... I could make it way more advanced but I'm not quite sure how you need it.

Link to comment
Share on other sites

Hi

 

Thanks for the help,

 

Maybe I can explain further.

 

I have a page for inputing user details, name address etc with optional drop down selections i.e chose country, all this works fine, except for the phone numbers, using a single text input box for this works fine for a single number.

 

But as contacts may have multiple pstn phone numbers, I would like to give the agents/users the option to chose from a list/drop down menu phone 1, phone 2, phone 3 etc then in a text input box beside this be able to type the number. If they for example chose phone 2 the number will get sent to the phone 2 field in the contacts table.

 

I can do this with multiple text input boxs but it seems better done as above.

 

This is what I have

 

Phone Number:

<select>

<option>Phone 1</option>

<option>Phone 2</option>

<option>Phone 3</option>

<option>Phone 4</option>

<option>Phone 5</option>

</select>

<input name="phone" type="text" value="<?php echo $phone; ?>">

 

So from the selection whatever is typed in the input box will goto the Phone1 field if chosen from the drop down in the contacts table.

 

Jason

Link to comment
Share on other sites

I understood the first time. The code I gave you is for that. Replace "drop_down_list" with the name of your select element, and replace "phone_number" with "phone" (now that I can see that this is the name of your text input).

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.