Re: array null after split string



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)
.



Relevant Pages

  • (patch for Bash) regex conditional tests
    ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: [PHP] Image Generation
    ... the text, font, colour, maximum frame size (ie the width and height it ... var $xoffset, $yoffset, $margin; ... a string or array of strings. ... a float or an array of floats - which size to display the related text at. ...
    (php.general)
  • Re: Reading from multiple serial ports in Delphi 7
    ... procedure ConnectSerial(var handle: THandle; deviceName: String; ... msg: String; ...
    (comp.lang.pascal.delphi.misc)
  • Re: RegExp: char -> /char
    ... :> But you said that you had the string already in a variable, ... var aFolders = new Array(); ...
    (microsoft.public.scripting.jscript)
  • Re: creating an array on the fly
    ... Dim myArray() As String ... Dim msg As String ... let's say the array is called arr, the string to add is called sStr. ...
    (microsoft.public.excel.programming)