PDA

View Full Version : simple split string problem


heaps21
02-16-2004, 05:38 PM
Can anyone tell me why the following gives me the error "Object doesnt support this property or method"? Im sure its something really simple, I just cant see it.


rota_name_array = array_string.split(",");
alert(rota_name_array.length);


btw - array_string = "a,b,c"

Vladdy
02-16-2004, 05:48 PM
Hard to tell without seeing complete code, better yet link to the page in question...

Willy Duitt
02-16-2004, 06:00 PM
Because you are trying to split array_string before it is defined?
Who knows, as Vladdy said, need more code...

BTW: This works:
<script>
array_string = "a,b,c"
rota_name_array = array_string.split(",");
alert(rota_name_array.length);
alert(rota_name_array[1].length)
</script>

.....Willy

heaps21
02-16-2004, 06:10 PM
Vladdy, Here is the code and the link is: www.heaps21.f2s.com/add_rota_type1.php (http://www.heaps21.f2s.com/add_rota_type1.php)

The code posted before is literally all I am trying to do at the moment though so there isnt much more to see there.

Ita all there for you anyway, cheers.

Vladdy
02-16-2004, 06:19 PM
Use correct way to access document objects:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html
http://www.w3.org/TR/DOM-Level-2-HTML/html.html

myForm = document.getElementById('formID');
or
myForm = document.forms['formName'];

elementValue = myForm.elements['elementName'].value;

Also avoid using with() until you are absolutely sure that you know what you are doing.

Willy Duitt
02-16-2004, 06:42 PM
As I said. You are not defining the array_string!
Where's the value being passed? It's not, it's undefined....

Try this:

rota_name_array = array_string.value.split(",");

.....Willy

heaps21
02-16-2004, 06:43 PM
ah yes thats much better thanks, but what is wrong with 'with' - I only used is coz i saw it in a script online somewhere :-)