By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,746 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,746 IT Pros & Developers. It's quick & easy.

dynamic value addition in the combo box

P: 3
Hi there to all.This is arwinder... i have a bit of a problem.. i cant think of the proper code for displaying the values that we select from an another combo box into a new one .. the moment we select a option it should be displayed in the new combo box. how should i do it.> please help.
the language used is php.along with a mysql.
Feb 23 '07 #1
Share this Question
Share on Google+
8 Replies

ronverdonk
Expert 2.5K+
P: 4,258
Welcome to The Scripts!

Please elaborate on your problem a bit more than you gave us now.

It must be clear that you can only do this (the moment we select a option it should be displayed in the new combo box) using JavaScript.

Ronald :cool:
Feb 23 '07 #2

P: 99
Hi there to all.This is arwinder... i have a bit of a problem.. i cant think of the proper code for displaying the values that we select from an another combo box into a new one .. the moment we select a option it should be displayed in the new combo box. how should i do it.> please help.
the language used is php.along with a mysql.
if you have a listboxe like this

[HTML]
<select name="select1[]" size="4">
<option value="test 1">test 1</option>
<option value="test 2">test 2</option>
<option value="test 3">test 3</option>
<option value="test 4">test 4</option>
</select>
<input type="submit" name="clone" value="clone">
[/HTML]

you can do
[PHP]
<select name="select2" size="4">
if($_POST['clone']){
foreach($_POST['select1'] as $copy){
echo '<option value="'.$copy.'">'.$copy.'</option>';
}
}
</select>
[/PHP]
Feb 23 '07 #3

P: 99
if you have a listboxe like this

[HTML]
<select name="select1[]" size="4">
<option value="test 1">test 1</option>
<option value="test 2">test 2</option>
<option value="test 3">test 3</option>
<option value="test 4">test 4</option>
</select>
<input type="submit" name="clone" value="clone">
[/HTML]

you can do
[PHP]
<select name="select2" size="4">
if($_POST['clone']){
foreach($_POST['select1'] as $copy){
echo '<option value="'.$copy.'">'.$copy.'</option>';
}
}
</select>
[/PHP]

the html of the second combo can go inside of the post if if you want the second combo box not to be visible without options.
Feb 23 '07 #4

ronverdonk
Expert 2.5K+
P: 4,258
xwero: your code works fine if you want to submit the form after selecting an entry.

But the question was: "the moment we select a option it should be displayed in the new combo box. ".

And that means without submitting the form: i.e. dynamically. Hence the required usage of JavaScript, probably the onchange() function.

Ronald :cool:
Feb 23 '07 #5

P: 99
xwero: your code works fine if you want to submit the form after selecting an entry.

But the question was: "the moment we select a option it should be displayed in the new combo box. ".

And that means without submitting the form: i.e. dynamically. Hence the required usage of JavaScript, probably the onchange() function.

Ronald :cool:
@ronverdonk:

I think you said somewhere this is a php forum so this is the php solution ;) I didn't say it i just offered the solution :)
Feb 23 '07 #6

ronverdonk
Expert 2.5K+
P: 4,258
I don't doubt your solution, but the post explicitly stated that requirement.

Maybe I should have posted my reply differently like: "this is not possible in PHP, but when you are prepared to use JS you can do it as a combination of PHP and JS".

Ronald :cool:
Feb 23 '07 #7

P: 3
thanks u guys...
i'll be more specific next time..
it was really helpful..
Feb 26 '07 #8

P: 1
I have a similiar issue. I can get the options to move from one combo box to the other that is not a problem. What I'm having problems doing is once I move the values over to this new box how do I create an array to POST the values to another PHP page.
Oct 13 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.