473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

resetting an HTML combo box

I have an HTML form which includes a combo box with 4 options, which is used
to select a method of contact (phone, email etc...). If the user selects an
invalid option (for example, they have selected phone, but have not supplied
a phone number) an alert box pops up. How do I reset the combo box so it
displays the first option in the combo box (which is the default)??

Many thanks in advance.
Jul 23 '05 #1
4 9105
"Richard Haygreen" <rj***@kent.ac.uk> wrote in message
news:cj**********@athena.ukc.ac.uk...
I have an HTML form which includes a combo box with 4 options, which is used to select a method of contact (phone, email etc...). If the user selects an invalid option (for example, they have selected phone, but have not supplied a phone number) an alert box pops up. How do I reset the combo box so it
displays the first option in the combo box (which is the default)??

Many thanks in advance.


document.{form_name}.{select_name}.selectedIndex = -1;

For example, watch for word-wrap.

<html>
<head>
<title>selreset.htm</title>
<script type="text/javascript">
function selected(that) {
var form1 = document.form1;
// substitute your validation below.
if (1==1) {
alert("Invalid selection!");
that.selectedIndex = -1;
}
}
</script>
</head>
<body>
<form name="form1">
<select name="ContactMethod"
onchange="selected(this)">
<option>
<option>Phone
<option>Email
<option>Pager
<option>Other
</select>
</form>
</body>
</html>
Jul 23 '05 #2
On Fri, 01 Oct 2004 15:01:30 GMT, McKirahan <Ne**@McKirahan.com> wrote:
"Richard Haygreen" <rj***@kent.ac.uk> wrote in message
news:cj**********@athena.ukc.ac.uk...
How do I reset the combo box so it displays the first option in the
combo box (which is the default)??

[snip]
document.{form_name}.{select_name}.selectedIndex = -1;


The OP asked for the first option. That removes any selection.

document.forms['formName'].elements['elementName'].selectedIndex = 0;

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Richard Haygreen wrote:
I have an HTML form which includes a combo box with 4 options, which is used
to select a method of contact (phone, email etc...). If the user selects an
invalid option (for example, they have selected phone, but have not supplied
a phone number) an alert box pops up. How do I reset the combo box so it
displays the first option in the combo box (which is the default)??

Many thanks in advance.


I would think carefully about re-setting it. If the user's input fails
validation, you are going to clear their selection and (presumably)
whatever they typed in. So as punishment for maybe one bad keystroke,
they now have to re-select (say) e-mail and type in maybe 15 characters
all over again.

Maybe what you are doing is fine, but just think about it from your
users' perspective.
Cheers, Fred.
Jul 23 '05 #4
> I would think carefully about re-setting it. If the user's input fails
validation, you are going to clear their selection and (presumably)
whatever they typed in. So as punishment for maybe one bad keystroke,
they now have to re-select (say) e-mail and type in maybe 15 characters
all over again.

Maybe what you are doing is fine, but just think about it from your users'
perspective.
Cheers, Fred.


Yes, I would agree with you, my intention is not to punish the user, but to
force them to make a selection. If they select phone, and have not entered a
phone number I want to reset the combo box; leaving them two choices: select
a different option or enter a phone number. At the moment the page tells the
user they have errored, but does nothing about it. I am trying to build in a
fail safe.

Many thanks for all your help.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: riprod | last post by:
Someone in the IIS newsgroup suggest I post this here, so sorry in advance for the cross posting. I have a Win 2003 SP1 with IIS 6 and host about 40 websites, most of them useing ASP/VB with...
1
by: SAN CAZIANO | last post by:
how can clear an html SELECT and next insert in it all the elements of an array () I try this but seems doesn't works. function ComboAddArrayValueWithLabel(combo,ArrayLabel,ArrayValue) { ...
2
by: DeveloperPDX | last post by:
I am creating a page and I need to add a reset button (like you would with HTML forms). Is there any way to do this other than resetting individual controls? Basically I need to page to return to...
5
by: Ant | last post by:
Hi, (Winform VS2003) I have a combo box bound to a typed data set. When the form loads, the combo box is popluated using a method containing the simple code below: ------------------------...
4
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I...
1
by: =?Utf-8?B?TWlrZSBNY0FsbGlzdGVy?= | last post by:
I have not been able to find anything about this problem, so it must be configuration on our server, somehow... What we are observing is on Windows Server 2003/IIS 6 our AJAX UpdatePanels are...
1
by: swapna.munukoti | last post by:
Hi all, Is there a way to display some text in html select control by default which when the control is clicked, will not be listed in the drop down that contains its options. For example:...
1
by: seeing | last post by:
hello i can change the button image using javascript but, i cant figure out how to *re-set* the button to its original state when a different button is pressed i.e button A = imageA.gif -...
8
by: bobh | last post by:
Hi All, Has anyone figured out how to reset the recordsource of a openned form?? ex: User opens a form, selects a value from combo1, selects a value from combo2, in the AfterUpdate event of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.