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

Automatically click a field

P: n/a
Hi,
can I have a field automatically clicked by calling something like
click()?
I have a dropdown box, one of whose elements is "Others (Please
Specify)". I list the dropdown boxes values alphabetically.
Sometimes, this value happens to be on the top and SELECTED. The problem
is that if this item is selected by clicking on it, in response to
onChange I open a text field (so user can specify the value). If this
field is automatically selected, the text field des not show; I have to
select another value then click on the "Other (please Specify)" to have
the text field visible.

Thanx.
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ivo
"Xerxes" wrote
Hi,
can I have a field automatically clicked by calling something like
click()?
Yes. Newer browsers implement that method for a variety of elements as the
references can tellyou.
I have a dropdown box, one of whose elements is "Others (Please
Specify)". I list the dropdown boxes values alphabetically.
Sometimes, this value happens to be on the top and SELECTED. The problem
is that if this item is selected by clicking on it, in response to
onChange I open a text field (so user can specify the value).
The problem is you rely on an onchange while sometimes there is none. Create
a dummy option, with a title text and no value, on top, so that one is
selected when there is none selected.

HTH
Ivo
If this
field is automatically selected, the text field des not show; I have to
select another value then click on the "Other (please Specify)" to have
the text field visible.

Thanx.

Jul 23 '05 #2

P: n/a
Thanks Ivo.
The problem with creating a dummy value is that the values of the
dropdown box are set by querying a database, sorted alphabetically. If I
use something like "Select something...", it might fall somewhere in the
middle of the list of values. Any way I can get around it? Can I assign
an index (of zero) to an option?

<SELECT>
<options are filled in from a database in a php file>
< option index=0 (??)>Make a selection</option>
</select>

Thanks.

"Ivo" <no@thank.you> wrote in message
news:40***********************@news.wanadoo.nl...
"Xerxes" wrote
Hi,
can I have a field automatically clicked by calling something like
click()?
Yes. Newer browsers implement that method for a variety of elements as

the references can tellyou.
I have a dropdown box, one of whose elements is "Others (Please
Specify)". I list the dropdown boxes values alphabetically.
Sometimes, this value happens to be on the top and SELECTED. The problem is that if this item is selected by clicking on it, in response to
onChange I open a text field (so user can specify the value).
The problem is you rely on an onchange while sometimes there is none.

Create a dummy option, with a title text and no value, on top, so that one is
selected when there is none selected.

HTH
Ivo
If this
field is automatically selected, the text field des not show; I have to select another value then click on the "Other (please Specify)" to have the text field visible.

Thanx.


Jul 23 '05 #3

P: n/a
Ivo
"Xerxes" wrote
Thanks Ivo.
The problem with creating a dummy value is that the values of the
dropdown box are set by querying a database, sorted alphabetically. If I
use something like "Select something...", it might fall somewhere in the
middle of the list of values. Any way I can get around it? Can I assign
an index (of zero) to an option?


Silly you! Can't you add the first option after the sorting has taken place?
Like with line no. 2 added to your code below:

1. > <SELECT>
2. <option value="">Look Ma, no sorting.
3. > <options are filled in from a database in a php file>
4. > </select>

If you need to have the options in an PHP array before anything else, have a
look at www.php.net/array_unshift.
HTH
Ivo
Jul 23 '05 #4

P: n/a
Xerxes wrote:
Hi,
can I have a field automatically clicked by calling something like
click()?
I have a dropdown box, one of whose elements is "Others (Please
Specify)". I list the dropdown boxes values alphabetically.
Sometimes, this value happens to be on the top and SELECTED. The problem
is that if this item is selected by clicking on it, in response to
onChange I open a text field (so user can specify the value). If this
field is automatically selected, the text field des not show; I have to
select another value then click on the "Other (please Specify)" to have
the text field visible.

Thanx.


<script type="text/JavaScript">
function replaceOptionWithPrompt(menu,msg){
if(menu.selectedIndex==menu.length-1){
var x=window.prompt(msg,"");
if(x){
menu[menu.length-1]= new Option(x,x);
menu[menu.length-1].selected=true;
}
}
}
</script>

<form>
<select name="jobs" onchange="replaceOptionWithPrompt(this,'Please
supply your job description')">
<option selected>Profession</option>
<option value="doc">Doctor</option>
<option value="atty">Lawyer</option>
<option value="realtor">Real Estate</option>
<option value="other">Other</option>
</select>
</form>

Mick
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.