473,398 Members | 2,812 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,398 software developers and data experts.

can I use confirm to stop a select list change?

Hi

I want to warn the user that changing the selected item in a pull-down
will clear some data he has already entered in a file download box.

I've tried using confirm() to return true or false with a line such as:

onchange="return(confirm('proceed Yes or No')))"
but it always stops the change.

Is what I'm trying to do possible?

John South
Pangbourne UK

Jul 23 '05 #1
4 20920
Jo**********@gmail.com wrote:
Hi

I want to warn the user that changing the selected item in a pull-down
will clear some data he has already entered in a file download box.

I've tried using confirm() to return true or false with a line such as:

onchange="return(confirm('proceed Yes or No')))"
There's one to many closing brackets...------^
But maybe that's just a posting typo.
but it always stops the change.
Stops what change?

You can't use onchange to prevent a user changing a selection - it
runs after they've made the change (usually when the element loses
focus, but not always).

Not sure what you mean by "a file download box" - you can't change
the value of a file input ( <input type="file" ...> ) other than to
clear it with reset if it's in a form.

Is what I'm trying to do possible?


So far, no, but maybe. Supply a bit more code or fuller explanation
to illustrate what you are trying to do.

A confirm gives the user an opportunity to conditionally execute some
script, I can't see that it has any use as the sole action of an
onchnage event.

Here's a bit of play code:

<form name="formA" action="">
<select name="selA" onchange="
if (confirm('Proceed Yes or No')){
selIdx = this.selectedIndex;
// Do whatever if user says OK
// ...
} else {
// Don't do it and return selection to previous
this.selectedIndex = selIdx;
}
">
<option selected>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</form>
<script type="text/javascript">
// Set selIdx to defalut selected index on page load
var selIdx = document.formA.selA.selectedIndex;
</script>
--
Rob
Jul 23 '05 #2
Rob,
Thanks for the clear and full reply. I think the answer to my question
is no, but I'll explain a bit more detail just in case you see an
opening:

On my form I have an input type="file" upload control and a number of
text boxes. I also have a select control to select the JobType. The
number of text boxes depends on the JobType. When the user selects a
JobType I do an "AutoPostBack" (asp.net c#) to refresh the page with
the correct text boxes. Unfortunately if the user has already browsed
for a file to upload, this is cleared with the refresh.

If the user changes the JobType I'd like to check if the file upload
control contains a value and, if so, warn the user that the control
will be cleared. I'd like to give him the chance to cancel and to
return the JobType to it's value before the last change, and not do the
auto call back.
Am I asking too much?

John South

Jul 23 '05 #3
ASM
Jo**********@mail.com wrote:
Rob,
Thanks for the clear and full reply. I think the answer to my question
is no, but I'll explain a bit more detail just in case you see an
opening:

On my form I have an input type="file" upload control and a number of
text boxes. I also have a select control to select the JobType. The
number of text boxes depends on the JobType. When the user selects a
JobType I do an "AutoPostBack" (asp.net c#) to refresh the page with
the correct text boxes.
I do not understand Why you have to refresh the page
only to change some fields.
Unfortunately if the user has already browsed
for a file to upload, this is cleared with the refresh.
Except if your php send back the right values
If the user changes the JobType I'd like to check if the file upload
control contains a value and, if so, warn the user that the control
will be cleared. I'd like to give him the chance to cancel and to
return the JobType to it's value before the last change, and not do the
auto call back.
Am I asking too much?


No, because I don't understand what exactly do the
onchange on select if I'd confirm.
Is this select a submit button ?

<select onchange="var n=this.options.selectedIndex;
var o = this.options[n].value
if(confirm('You\'re sure of your choice?\nif OK page will change'))
{ document.myForm.ind.value = o;
document.myForm.submit(); }
else
{ alert('No change done');
this[0].selected=true;
document.myForm.ind.value = '';}">

document.myForm.ind is a hidden field initially empty
(to tell to php what to do)

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #4
Jo**********@gmail.com wrote:
Rob,
Thanks for the clear and full reply. I think the answer to my question
is no, but I'll explain a bit more detail just in case you see an
opening:

On my form I have an input type="file" upload control and a number of
text boxes. I also have a select control to select the JobType. The
number of text boxes depends on the JobType. When the user selects a
JobType I do an "AutoPostBack" (asp.net c#) to refresh the page with
the correct text boxes. Unfortunately if the user has already browsed
for a file to upload, this is cleared with the refresh.

If the user changes the JobType I'd like to check if the file upload
control contains a value and, if so, warn the user that the control
will be cleared. I'd like to give him the chance to cancel and to
return the JobType to it's value before the last change, and not do the
auto call back.
Am I asking too much?


I'm not familiar with ASP.NET or C#, I imagine that an onchange
function is being created for the client-side page that either posts
back the form or uses XMLHTTPrequest to get new content for the page.

Either way, you need to post whatever is being delivered to the client.
The code I posted above conditionally changes a select back to the
previous selection. You need to insert something like that into the
onclick generated by the ASP page (if there is one) or code it
yourself.

Although you can't change the file input's value, you can read it. So
test if it's empty and respond accordingly:
<form name="formA" action="">
<input type="file" name="xx"><br>
<select name="selA" onchange="
if ( '' != this.form.xx.value )
if ( ! confirm('Proceed Yes or No')){
// Return selection to previous & don't proceed
this.selectedIndex = selIdx;
return;
}
}
// Remember selection, do stuff 'cos user said OK
// or hasn't selected a file yet
selIdx = this.selectedIndex;
// ...
}
">
<option selected>option 1</option>
<option>option 2</option>
<option>option 3</option>
</select>
</form>
<script type="text/javascript">
// Set selIdx to default selected index on page load
var selIdx = document.formA.selA.selectedIndex;
</script>
An alternative is to put all of your fields in the form, then hide or
show groups of them depending on which selection the user has made.
Then they don't loose anything that they've already filled in.

This approach should display all the fields by default and use script
to hide them. Then if a user doesn't have scripting enabled, they can
still use the form (autpostback depends on client-side scripting).
--
Rob
Jul 23 '05 #5

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

Similar topics

4
by: zsh-users-help | last post by:
Hi! This is the ezmlm program. I'm managing the zsh-users@sunsite.dk mailing list. To confirm that you would like python-list@python.org removed from the zsh-users mailing list, please send...
2
by: Hans | last post by:
Hi! I have an asp application where I use a lot of javascript for validations etc and as it is today I use alert, confirm and prompt dialogs. Now we are adding support for unicode and I have...
7
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
1
by: Joe Attardi | last post by:
Hi all, On a form on one of my pages I have two <select> elements, and each one is paired up with a radio button. The idea is to choose an item from one list or the other and select the radio...
5
by: robert | last post by:
I have a dropdownlist with the autopostback set to true. I want the user to be confirm whether they do indeed want to change the value, which on post back fires a server side event...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
2
by: lavender | last post by:
I have one C programming problem: Enter value, 0 to stop: 15 26 45 0 List now : 15 26 45 0 37814140 Value to change : 26 Want to change with value: 45
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
1
by: SimoRed | last post by:
Hi, I have a combobox with a list of links and I want to redirect (after confirming it) to a link with onChange. I use: onChange="if (confirm('do you want to redirect?')) {...
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
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
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
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,...

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.