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).