473,395 Members | 1,554 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,395 software developers and data experts.

dropdownlist question

Hi, I have the following Javascript that fires from an onChange event
for a dropdownlist. When the dropdownlist changes, it shows a dialog
box with Yes and Cancel. If I press Cancel, I want the value currently
in the dropdownlist to be reset back to what it was before. How do you
do reset it back?

Thank you a lot in advance
David

<script>
function pleaseConfirm()
{
return confirm("confirm you want to do this");
}
</script>
Jul 23 '05 #1
3 2392
Ok -- found your question while I was looking to solve the same problem --
didn't find a good answer anywhere -- so here's the resolution that I came
up with -- and works quite well for my intended functionality, which is to
make certain that before a user changes a drop down that they receive a
"confirmation" box and must answer "ok" prior to actually being able to
change said drop down value.

<select name="dropdownArea"
onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Now -- had to use the onFocus event as opposed to using the onChange event
-- as using the latter would have entailed that I reset the form values
(or something) to be able to get back the original drop down value if they
did not click "ok". And by blurring the focus -- until they hit "ok" --
they'll receive the confirmation box when they set focus on the dropdown.

Additionally, I added a default state -- in this case "< Select Option >"
-- I didn't want it to ask them of the dropdown was on this default state
-- so modified as follows:

<select name="dropdownArea"
onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
this.blur(); };}">
<option value="-1">&lt; Select Option &gt;</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Hope that helps -- if you find alternate means of accomplishing this --
I'd be interested in seeing it...

...Lance W. Larsen
www.lancelarsen.com

Jul 23 '05 #2
Ok -- found your question while I was looking to solve the same problem --
didn't find a good answer anywhere -- so here's the resolution that I came
up with -- and works quite well for my intended functionality, which is to
make certain that before a user changes a drop down that they receive a
"confirmation" box and must answer "ok" prior to actually being able to
change said drop down value.

<select name="dropdownArea"
onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Now -- had to use the onFocus event as opposed to using the onChange event
-- as using the latter would have entailed that I reset the form values
(or something) to be able to get back the original drop down value if they
did not click "ok". And by blurring the focus -- until they hit "ok" --
they'll receive the confirmation box when they set focus on the dropdown.

Additionally, I added a default state -- in this case "< Select Option >"
-- I didn't want it to ask them of the dropdown was on this default state
-- so modified as follows:

<select name="dropdownArea"
onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
this.blur(); };}">
<option value="-1">&lt; Select Option &gt;</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Hope that helps -- if you find alternate means of accomplishing this --
I'd be interested in seeing it...

...Lance W. Larsen
www.lancelarsen.com

Jul 23 '05 #3
Ok -- found your question while I was looking to solve the same problem --
didn't find a good answer anywhere -- so here's the resolution that I came
up with -- and works quite well for my intended functionality, which is to
make certain that before a user changes a drop down that they receive a
"confirmation" box and must answer "ok" prior to actually being able to
change said drop down value.

<select name="dropdownArea"
onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Now -- had to use the onFocus event as opposed to using the onChange event
-- as using the latter would have entailed that I reset the form values
(or something) to be able to get back the original drop down value if they
did not click "ok". And by blurring the focus -- until they hit "ok" --
they'll receive the confirmation box when they set focus on the dropdown.

Additionally, I added a default state -- in this case "< Select Option >"
-- I didn't want it to ask them of the dropdown was on this default state
-- so modified as follows:

<select name="dropdownArea"
onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
this.blur(); };}">
<option value="-1">&lt; Select Option &gt;</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>

Hope that helps -- if you find alternate means of accomplishing this --
I'd be interested in seeing it...

...Lance W. Larsen
www.lancelarsen.com

Jul 23 '05 #4

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

Similar topics

2
by: Newbie | last post by:
I have a C# asp.net webform that contains a dropdownlist and a button that allows the user to select another item in the dropdownlist. The webform should work as follows: When the user selects...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
1
by: | last post by:
This is a crosspost from a less-frequented (but more focused) asp.net group; I didn't receive an answer that worked. I'd like to get this form functional. Could someone help on what's probably a...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
1
by: Phil | last post by:
I would like to make the CreateUserWizard's security question box display as a databound (xml file) dropdownlist. I can make the dropdownlist display by using a contenettemplate, but I can't get...
0
by: Juanjo | last post by:
Hi, Before, I was working with Asp.net 1.0 and datagrid. I posted a question for this issue. The solution of this problem is load the second dropdownlist on the selectedindexchanged event of the...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
1
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.