473,782 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9118
"Richard Haygreen" <rj***@kent.ac. uk> wrote in message
news:cj******** **@athena.ukc.a c.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_n ame}.selectedIn dex = -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.selectedIn dex = -1;
}
}
</script>
</head>
<body>
<form name="form1">
<select name="ContactMe thod"
onchange="selec ted(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.a c.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_n ame}.selectedIn dex = -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
18771
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 access databases. The server is a Dell Dual 2.4Ghz XEON with 512Mb Ram. Every few days I get the error 'HTTP/1.1 New Session Failed' and the server stops showing the sites. It comes right after a bit and then the error comes back. I
1
10127
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) { combo.options.length = 0; for (i=0; i<ArrayLabel.length; i++) combo.options = new Option(ArrayLabel,ArrayValue); }
2
1816
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 the state after the OnLoad event
5
2251
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: ------------------------ // Fill the datasets for the combo boxes daDepartment.Fill(dsDepartment.Departments);
4
4084
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 have to click it twice to do the job (the first submit resets the sessions but this it too late to change the field values, which requires another submit to pick up the new session values). Problem is I cant think how to accomplish the resetting of...
1
7188
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 not resetting the IIS Session timer. Thus, if the default IIS Session Timeout of 20 minutes is used, our logged-in users are always receving Session timeout in 20 minutes, regardless of what UpdatePanel activity is happening on the .aspx page. ...
1
2894
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: When I open a page, there is a combo box with "Select" displayed in that. It looks like that item is selected. But when I click that combo box, it does not list "Select" in the drop down. Instead it lists the
1
1111
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 - when pressed the image changes to imageA2.gif
8
10612
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 combo2 write the sql for the recordsource using those two choosen values then do a me.recordsource = strSQL me.requery
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7486
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.