Connecting Tech Pros Worldwide Forums | Help | Site Map

How to make options selected by default?

Ming
Guest
 
Posts: n/a
#1: Dec 11 '07
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,

Rik Wasmus
Guest
 
Posts: n/a
#2: Dec 11 '07

re: How to make options selected by default?


On Tue, 11 Dec 2007 18:27:27 +0100, Ming <minghuiyu@gmail.comwrote:
Quote:
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
Steve
Guest
 
Posts: n/a
#3: Dec 11 '07

re: How to make options selected by default?



"Ming" <minghuiyu@gmail.comwrote in message
news:bad68652-b509-4362-900d-ae4a3f75a46c@s19g2000prg.googlegroups.com...
Quote:
>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 ?>
Quote:
>&nbsp;&nbsp;<?= $item ?>
<br>
<?
}
}
?>
<input type="submit" value="Save And Refresh">
</form>


Steve
Guest
 
Posts: n/a
#4: Dec 11 '07

re: How to make options selected by default?



"Steve" <no.one@example.comwrote in message
news:e7A7j.32$%91.17@newsfe05.lga...
Quote:
>
"Ming" <minghuiyu@gmail.comwrote in message
news:bad68652-b509-4362-900d-ae4a3f75a46c@s19g2000prg.googlegroups.com...
Quote:
>>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!


Closed Thread