...

View Full Version : which button?



jessie_buns
05-30-2005, 09:11 AM
Hi All, I am really new to this so if someone can help thanks

I have put together some code to be prompted to open a file. Only I can not figure out how to hook into the event triggered by pressing the 'OK' or 'Cancel' buttons in the dialog.

Also can someone explain the line:

onclick='document.all.hiddenFileName.click()'


THANKS Jess

--------

<SCRIPT type="text/javascript">
function fnUpdatetext(e)
{
alert("filename " + e);
fnFilenname();
}

</script

<FORM name="dummy" >
<INPUT type="file" class="file" style="display: none" name="hiddenFileName" onchange='fnUpdatetext(this.value)'>
<input type="button" value="Cancel" onclick='alert("cancel button pressed")'>
<input type="text" style="visibility:hidden" name="Filename" >

<input type="button" name="openFile" width=40 height=18 style="position:absolute;top:0px;left:600px" value="open file"
onclick='document.all.hiddenFileName.click()'
>
</FORM>

vwphillips
05-30-2005, 10:05 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body>
<SCRIPT type="text/javascript">
function fnUpdatetext(e)
{
if (document.getElementById('Filename').style.visibility=='hidden'){
document.getElementById('Filename').style.visibility='visible';
document.getElementById('openFile').value='cancel';
document.getElementById('hiddenFileName').style.display='block';
}
else {
document.getElementById('Filename').style.visibility='hidden';
document.getElementById('openFile').value='open file';
document.getElementById('hiddenFileName').style.display='none';
}
}

function fnUpdatetext2(v){
document.getElementById('Filename').value=v;
}

</script>

<FORM name="dummy" >
<INPUT type="file" class="file" style="display:none" id="hiddenFileName" name="hiddenFileName" onchange='fnUpdatetext2(this.value)'>
<input id="Filename" type=text style="visibility:hidden;" name="Filename" >

<input type="button" id="openFile" name="openFile" width=40 height=18
style="position:absolute;top:0px;left:600px" value="open file"
onclick='fnUpdatetext()'
>
</FORM>
</body>

</html>

jessie_buns
05-30-2005, 11:00 AM
No, that's not what I want.

The code below invokes a file open dialog, but it does not work correctly every time. It only works correctly when the user chooses a different file over the one displayed and presses OK.


Do the following:
Press 'file Open' Select a file, press OK - file name displayed (close it)
press 'file open' press 'OK' to currently selected file - no display
It's only triggered on OK and onChange event occuring

Obviously it would be much better to hook into the return value from dialog. How do you do this?

<SCRIPT type="text/javascript">
function fnUpdatetext(e)
{
alert("filename " + e);
}

</script

<FORM name="dummy" >
<INPUT type="file" class="file" style="display: none" name="hiddenFileName" onchange='fnUpdatetext(this.value)'>

<input type="text" style="visibility:hidden" name="Filename" >

<input type="button" name="openFile" width=40 height=18 style="position:absolute;top:0px;left:600px" value="open file"
onclick='document.all.hiddenFileName.click()'
>
</FORM>

glenngv
05-30-2005, 12:14 PM
onchange was not triggered because there is no change in the value of the input file. That's the expected behavior. Do you want onchange to be always invoked even if there is no change in the value?

jessie_buns
05-30-2005, 12:42 PM
I understand the event and this event would work if I forced the filename value to be NULL before invoking the dialog. But that is nasty and it changes the expected behaviour of the dialog. All I want to know is:

How do I find out what message was thrown in the File Open Dialog to close it? :confused:

glenngv
05-30-2005, 01:06 PM
How do I find out what message was thrown in the File Open Dialog to close it? :confused:
There's no way to know what button is clicked.

jessie_buns
05-30-2005, 01:41 PM
There's no way to know what button is clicked.


I don't think so.

glenngv
05-30-2005, 01:55 PM
I don't think so.
So how? :rolleyes:
AFAIK, there's no way to know what the File Dialog returns in the same way the confirm() method does. That is because, you're not directly calling a function to open the File Dialog. It is internally invoked by a built-in File input element which the programmer has no control of.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum