array null after split string

E

edoardo.poeta

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>
 
E

Evertjan.

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:

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>
 
D

Dag Sunde

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 "]".
 
E

edoardo.poeta

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:

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top