a form that selects data and/or adds to menu choices

I want to design a form

there are two form input elements

option select

and

textbox





------------------
if user enters data into textbox
then
do not use option select
add to option select menu choices
mysql insert into categories column


else if user choses option select
use option select menu choice

------


sample data:

categories option select:
electronics
silverwear
bedding

textbox:
user enters new category: keyboards


now option select:
electronics
silverwear
bedding
keyboards
LVL 1
rgb192Asked:
Who is Participating?
 
Jagadishwor DulalConnect With a Mentor Braces MediaCommented:
I think you want some thing like the example below, Hope you will manage php and database codes :

<html>
<head>
<title> Test</title>
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(window).load(function(){
var $category = $('#category'),
$newcategory = $('#newcategory');
$category.change(function() {
if ($category.val() == 'other') {
$newcategory.removeAttr('disabled');
} else {
$newcategory.attr('disabled', 'disabled').val('');
}
}).trigger('change'); 
});
</script>
</head>
<body>
<label>Select Category</label>
<select id="category" class="category" name="category">
<option value="electronics">Electronics</option>
<option value="silverwear">Silverwear</option>
<option value="bedding">Bedding</option>
<option value="other">Other</option>
</select><br/>
<label>Enter New Category</label><input id="newcategory" class="text" type="text" name="newcategory" disabled="">
</body>
</html>

Open in new window

0
 
Ahmed MerghaniSoftware EngineerCommented:
Hello,

Your PHP code will be something like this:

if($_POST['text_input']  != ""){
     //code to insert the new category option in the database
}else if($_POST['option_select']  != ""){
    //use the selected option menu
}
0
 
rgb192Author Commented:
works great

only lets user enter text data when dropdown is chosen

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.