wrote on 31 aug 2006 in comp.lang.javascript
:
I'm a dummy. I have a basic knowledge of javascript and I want to split
a string, but I receive an error at line 15. Where my error in make the
array? Why? Can someone help me to resolve? Thank's.
The name of file is
E:\delibere test\pdf\2002\2002-01-01-GC-000-Testo.pdf
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JAVASCRIPT>
deprecated, use:
<script type='text/javascript'>
function verify(){
var estremi = new Array();
you do not need new Array(),
as it will be reassigned by split() anyway
var entrata = new String;
var msg = new String;
new String not needed, use:
var estremi,entrata, msg
entrata = document.fs.File1.value
more complete and versatile:
entrata = document.forms['fs'].elements['File1'].value
estremi = entrata.split["-"];
This [] is your ERROR, use:
estremi = entrata.split("-");
msg = "E\' corretto questo anno? \n" + estremi[0];
Escaping the ' is not necessaty, do:
msg = "E' corretto questo anno?\n'" + estremi[0] + "'";
//all we have to do is return the return value of the confirm()
method
return confirm(msg);
}
</SCRIPT>
</HEAD>
<BODY>
<H1>File Upload</H1>
<H2>To File System</H2>
<FORM method="post" encType="multipart/form-data"
action="ToFileSystem.asp" name="fs" onsubmit= "return verify()">
<INPUT type="File" name="File1">
<INPUT type="Submit" value="Upload">
</FORM>
</BODY>
</HTML>
Try:
<script type='text/javascript'>
function verify(theForm){
var estremi,entrata, msg;
entrata = theForm.elements['File1'].value;
estremi = entrata.split('-');
msg = "E' corretto questo anno?\n'" + estremi[0] + "'";
return confirm(msg);
};
</script>
<FORM method='post' encType='multipart/form-data'
action='ToFileSystem.asp' onsubmit= 'return verify(this);'>
<INPUT type='File' name='File1'>
<INPUT type='Submit' value='Upload'>
</FORM>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)