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

listbox with locked lines

P: n/a
Hi,

I have this listbox and I would like to lock some of the lines so that
the user can't select them. It's the 2 main areas "2798 Mokka"
and "3892 Juice" I don't won't the user to be able to select.
basically alle the lines that has a numer in front of the title needs
to be locked.

Please help! :)

<select name="ListBox" size="5" multiple="multiple" id="ListBox">

<option>2798 Mokka</option>
<option>indian blend</option>
<option>arabian blend</option>
<option>3892 Juice</option>
<option>Orange juice</option>
<option>cucumber juice</option>

</select>

Jan 7 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mokka wrote:
I have this listbox and I would like to lock some of the lines so that
the user can't select them. It's the 2 main areas "2798 Mokka"
and "3892 Juice" I don't won't the user to be able to select.
basically alle the lines that has a numer in front of the title needs
to be locked.
Use the `optgroup' element instead.
[...]
<select name="ListBox" size="5" multiple="multiple" id="ListBox">

<option>2798 Mokka</option>
<option>indian blend</option>
<option>arabian blend</option>
<option>3892 Juice</option>
<option>Orange juice</option>
<option>cucumber juice</option>

</select>


<select name="ListBox" size="5" multiple="multiple">
<optgroup label="2798 Mokka">
<option>indian blend</option>
<option>arabian blend</option>
</optgroup>
<optgroup label="3892 Juice">
<option>Orange juice</option>
<option>cucumber juice</option>
</optgroup>
</select>
PointedEars
Jan 7 '06 #2

P: n/a
Thomas 'PointedEars' Lahn wrote:

<select name="ListBox" size="5" multiple="multiple">
<optgroup label="2798 Mokka">
<option>indian blend</option>
<option>arabian blend</option>
</optgroup>
<optgroup label="3892 Juice">
<option>Orange juice</option>
<option>cucumber juice</option>
</optgroup>
</select>


Or:
<script type="text/javascript">
function getCategory(opt){
return opt.parentNode.label;
}
</script>
<form action="">
<select name="listBox" size="6"
onchange="this.form.x.value=getCategory(this[this.selectedIndex]);">
<optgroup label="2798 Mokka">
<option>indian blend</option>
<option>arabian blend</option>
</optgroup>
<optgroup label="3892 Juice">
<option>orange juice</option>
<option>cucumber juice</option>
</optgroup>
</select>
<input name="x" type="text" readonly value="">
</form>
Mick
Jan 7 '06 #3

P: n/a
mick white wrote:
Thomas 'PointedEars' Lahn wrote:
<select name="ListBox" size="5" multiple="multiple">
<optgroup label="2798 Mokka">
<option>indian blend</option>
<option>arabian blend</option>
</optgroup>
<optgroup label="3892 Juice">
<option>Orange juice</option>
<option>cucumber juice</option>
</optgroup>
</select>
Or:


Or?
<script type="text/javascript">
function getCategory(opt){
return opt.parentNode.label;
}
</script>
<form action="">
<select name="listBox" size="6"
onchange="this.form.x.value=getCategory(this[this.selectedIndex]);">
<optgroup label="2798 Mokka">
<option>indian blend</option>
<option>arabian blend</option>
</optgroup>
<optgroup label="3892 Juice">
<option>orange juice</option>
<option>cucumber juice</option>
</optgroup>
</select>
<input name="x" type="text" readonly value="">
</form>


That is an interesting solution, yet not one that address the OP's wish:

| It's the 2 main areas "2798 Mokka" and "3892 Juice" I don't won't the
| user to be able to select.

And it introduces a dependency to client-side scripting for no obvious
reason, so I really wonder why you posted it in the first place.
PointedEars
Jan 7 '06 #4

P: n/a
On 2006-01-06, Mokka <pr**********@gmail.com> wrote:
Hi,

I have this listbox and I would like to lock some of the lines so that
the user can't select them. It's the 2 main areas "2798 Mokka"

<select name="ListBox" size="5" multiple="multiple" id="ListBox">

<option disabled="disabled" >2798 Mokka</option>
<option>indian blend</option>
<option>arabian blend</option>
<option disabled="disabled" >3892 Juice</option>
<option>Orange juice</option>
<option>cucumber juice</option>

</select>

HTH.

Bye.
Jasen
Jan 8 '06 #5

P: n/a
Thomas 'PointedEars' Lahn wrote:
mick white wrote: [...]

That is an interesting solution, yet not one that address the OP's wish:

| It's the 2 main areas "2798 Mokka" and "3892 Juice" I don't won't the
| user to be able to select.

And it introduces a dependency to client-side scripting for no obvious
reason, so I really wonder why you posted it in the first place.


Just free flowing thoughts put to paper...
Cheers.
Mick
Jan 8 '06 #6

P: n/a
Jasen Betts wrote:
On 2006-01-06, Mokka <pr**********@gmail.com> wrote:
I have this listbox and I would like to lock some of the lines so that
the user can't select them. It's the 2 main areas "2798 Mokka"


<select name="ListBox" size="5" multiple="multiple" id="ListBox">

<option disabled="disabled" >2798 Mokka</option>
<option>indian blend</option>
<option>arabian blend</option>
<option disabled="disabled" >3892 Juice</option>
<option>Orange juice</option>
<option>cucumber juice</option>

</select>


In HTML, boolean attributes like `multiple' and `disabled' have no value,
the above is X(HT)ML syntax. And there is no need for `disabled', since
the `optgroup' element exists since HTML 4 as well as the `disabled'
attribute does. In contrast, UAs not supporting the `disabled' attribute
for some reason (such as HTML 3.2 support only), will allow to select the
respective `option' element anyway.

So this is not a viable solution.
PointedEars
Jan 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.