Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / August 2006



Tip: Looking for answers? Try searching our database.

array null after split string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
edoardo.poeta@gmail.com - 31 Aug 2006 09:41 GMT
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>
Evertjan. - 31 Aug 2006 10:14 GMT
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
[quoted text clipped - 6 lines]
> <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
[quoted text clipped - 14 lines]
> </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>

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

edoardo.poeta@gmail.com - 31 Aug 2006 10:56 GMT
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:
>
[quoted text clipped - 85 lines]
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
Dag Sunde - 31 Aug 2006 10:18 GMT
> 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
[quoted text clipped - 12 lines]
>    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 "]".

Signature

Dag.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.