By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

array null after split string

P: n/a
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>
function verify(){
var estremi = new Array();
var entrata = new String;
var msg = new String;
entrata = document.fs.File1.value
estremi = entrata.split["-"];
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>

Aug 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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)
Aug 31 '06 #2

P: n/a
ed***********@gmail.com wrote:
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>
function verify(){
var estremi = new Array();
var entrata = new String;
var msg = new String;
entrata = document.fs.File1.value
estremi = entrata.split["-"];
<snipped/>

estremi = entrata.split("-");

split is a function, thus you must use "(" and ")", not
square brackets "[" and "]".

--
Dag.

Aug 31 '06 #3

P: n/a
Thank you!
I used the name of the form and not "This". Mysterious javascript ;-)

Evertjan. ha scritto:
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)
Aug 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.