?
Solved

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

Posted on 2012-09-03
3
Medium Priority
?
392 Views
Last Modified: 2012-09-04
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
0
Comment
Question by:rgb192
3 Comments
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 38362490
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
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 2000 total points
ID: 38362505
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
 

Author Closing Comment

by:rgb192
ID: 38365124
works great

only lets user enter text data when dropdown is chosen

thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question