Connecting Tech Pros Worldwide Forums | Help | Site Map

dropdownlist question

David
Guest
 
Posts: n/a
#1: Jul 23 '05
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>

lancewlarsen
Guest
 
Posts: n/a
#2: Jul 23 '05

re: dropdownlist question


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

lancewlarsen
Guest
 
Posts: n/a
#3: Jul 23 '05

re: dropdownlist question


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

lancewlarsen
Guest
 
Posts: n/a
#4: Jul 23 '05

re: dropdownlist question


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

Closed Thread