Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using split in .asp page

Status
Not open for further replies.

adknbvi

Programmer
Apr 17, 2001
25
0
0
US
I am having the most ridiculous problems getting the split method to do what I want. All I am trying to do is split a string using the carat (^) as a delimiter. Here is the code for two simple pages: an htm file and the asp file that it posts to. I know the answer must be simple, but I am apparently looking through it at this point.

test1.htm
Code:
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>Test Page 1</title>
</head>
<body>
<form name=frmTest action=&quot;test2.asp&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;hidStateCodeList&quot; value=&quot;NY^PA&quot;>
<input type=&quot;submit&quot; name=&quot;btnTry&quot; value=&quot;Push this button&quot;>
</form>
</body>
</html>

test2.asp
Code:
<%@ language = JavaScript %>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>Test2</title>
</head>
<body>
<%
	var strStateCodeList = Request.Form(&quot;hidStateCodeList&quot;);
	Response.Write(strStateCodeList);
	var arChoices = strStateCodeList.split('^');
	//Response.Write(arChoices[0]);
%>
</body>
</html>

Every time I run this, I can see the correct contents of strStateCodeList (from the Response.Write command) and then I receive the following error:

Code:
Microsoft JScript runtime error '800a01b6' 

Object doesn't support this property or method 

/PS/test2.asp, line 14

Any help with this would be appreciated!
Valerie
 
A quick look shows an error here...
strStateCodeList.split('^');

Try this...
MyArray = Split(MyString, &quot;^&quot;)

You split the string into an array! Also, I don't understand your use of 'var'. If this is asp, you should either 'dim' your variables, or not do anything. But I'd recommend 'dim'.

Mike
 
Mike,
This is an asp file, but the language is JavaScript, that is why I used the syntax that I did for the .split and the &quot;var&quot; to dimension my variable.

Thanks,
Valerie
 
Valerie,

oops, i totally missed <%@ language = JavaScript %>. My bad. I shut up now...ok...since my js is a bit on the shady side, don't you need to declare your array...myarray=new Array()? just a thought.

Mike
 
No problem, Mike. I have tried with and without the separate declaration for the array, and neither have worked. The frustrating part is that I have written it exactly as I have read it from several of my reference books (with/without the array declaration, with/without using a variable to indicate the value of the separator). I am so sure that it is something I am overlooking.
 
Valerie,

My suggestion is to break down the split section to its simplest form, just to make sure the split function works as you want it to. Then plug it in. I did a quick one:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY BGCOLOR=&quot;#FFFFFF&quot;>
<script language=javascript>
var somestring=&quot;my dog is named skip&quot;;
var somearray=new Array();
somearray=somestring.split(&quot; &quot;);

var elem;
for (elem in somearray)
{
alert(somearray[elem]);
}
alert (somearray.length);
</script>
</BODY>
</HTML>

Because I never worked with js this way, perhaps its the comment tag? //Response.Write(arChoices[0]);
Try removing this line. I don't know if that's a valid comment in js this way (is this server side js?). Just a thought. Sorry I can't give you a more exact answer.

Mike
 
Try using double quote instead. Like this: var arChoices = strStateCodeList.split(&quot;^&quot;)(just a suggestion). Also check to see if method split() can be use in asp. One more thing, I you using the form name=&quot;frmTest&quot;, try taking it off if not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top