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

How to make options selected by default?

P: n/a
I have two list box (A and B), and I have two buttons to move list
items (options)
from this box to the other.I have a submit button to submit the form.

I know how to move items from A to B by using Javascript, and I know
how to use <option ... selectedto select an item.

However, how can I select an item after the page is rendered? In other
words, A and B have been populated with data and the page is rendered.
I click the move items button to move other items from A to B. I want
all items in B are selected.

Thanks,
Dec 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 11 Dec 2007 18:27:27 +0100, Ming <mi*******@gmail.comwrote:
I have two list box (A and B), and I have two buttons to move list
items (options)
from this box to the other.I have a submit button to submit the form.

I know how to move items from A to B by using Javascript, and I know
how to use <option ... selectedto select an item.

However, how can I select an item after the page is rendered? In other
words, A and B have been populated with data and the page is rendered.
I click the move items button to move other items from A to B. I want
all items in B are selected.
=comp.lang.javascript
Just select it just after you add the it to the b <selectwith
javascript. Alternatively, just select every item in B in the onsubmit()
action of your form. Be very, very aware offcourse this will break all
functionality for those without javascript.
--
Rik Wasmus
Dec 11 '07 #2

P: n/a

"Ming" <mi*******@gmail.comwrote in message
news:ba**********************************@s19g2000 prg.googlegroups.com...
>I have two list box (A and B), and I have two buttons to move list
items (options)
from this box to the other.I have a submit button to submit the form.

I know how to move items from A to B by using Javascript, and I know
how to use <option ... selectedto select an item.

However, how can I select an item after the page is rendered? In other
words, A and B have been populated with data and the page is rendered.
I click the move items button to move other items from A to B. I want
all items in B are selected.
simplest break-down i could think of...

<?
$items = isset($_REQUEST['items']) ?
$_REQUEST['items'] :
array();
$myItems['A List'][] = 'Hello';
$myItems['A List'][] = 'World';
$myItems['B List'][] = 'B';
?>
<form method="post">
<?
foreach ($myItems as $type =$defined)
{
foreach ($defined as $index =$item)
{
$selected = isset($items[$type][$index]) ? 'checked' : '';
?>
<input name="items[<?= $type ?>][<?= $index ?>]"
type="checkbox"
value="<?= $item ?>"
<?= $selected ?>
>&nbsp;&nbsp;<?= $item ?>
<br>
<?
}
}
?>
<input type="submit" value="Save And Refresh">
</form>
Dec 11 '07 #3

P: n/a

"Steve" <no****@example.comwrote in message
news:e7*************@newsfe05.lga...
>
"Ming" <mi*******@gmail.comwrote in message
news:ba**********************************@s19g2000 prg.googlegroups.com...
>>I have two list box (A and B), and I have two buttons to move list
items (options)
from this box to the other.I have a submit button to submit the form.

I know how to move items from A to B by using Javascript, and I know
how to use <option ... selectedto select an item.

However, how can I select an item after the page is rendered? In other
words, A and B have been populated with data and the page is rendered.
I click the move items button to move other items from A to B. I want
all items in B are selected.

simplest break-down i could think of...

<?
$items = isset($_REQUEST['items']) ?
$_REQUEST['items'] :
array();
$myItems['A List'][] = 'Hello';
$myItems['A List'][] = 'World';
$myItems['B List'][] = 'B';
two things...first, based on your description, subtract the submitted items
from your default lists...

$myItems['A List'] = array_diff_assoc($myItems['A List']);
$myItems['B List'] = array_diff_assoc($myItems['B List']);

second, change the original same to be options of a list box rather than
just the check boxes. ah screw it...give me a second to repost the answer. i
should have read your post better to begin with!
Dec 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.