...

View Full Version : Problems with String manipulation in form processing



Kinokunya
02-09-2003, 06:05 AM
Hi guys,

i'm currently experiencing problems manipulating string data from the forms i've submitted. JScript user here.

What i basically did was to create 2 ASP pages, i'll just name it page 'A' and 'B'.

Page 'A' has a textfield called 'songTitle', while page 'B' uses the Request.Form("songTitle") method to retrieve out back the String back right?

Due to the fact that i'll need to do some truncating using the strObj.split( ) method to delimit some of the crap underscores, etc etc in the songTitle attribute, but it turns out that the Request.Form method returns the String object as a read-only String.

Any idea how i can get around this problem so that i can still manipulate the text?

Leeus
02-09-2003, 09:46 PM
On page B declare a new variable,

See this



<%
dim songtitle
songtitle = Request.Form("songTitle")



%>

;)
You now have a variable that you can play around with.

Kinokunya
02-10-2003, 04:01 AM
hmmz .. i'd tried that in Jscript, but it doesn't seem to work for me:(

here's what i did, a simple test if the text is still read-only;

<%
...
var title, newStr;
title = Request.Form("hTitle");
newStr = title.concat("concatTest");
Response.Write("Keyed in Title is: " + newStr);
...
%>



The scripting engine gave me this as an error;

Microsoft JScript runtime error '800a01b6'
Object doesn't support this property or method


Edited: oh, thanks for the vb scriptlet Leeus, it seems that when using vbscript, there's no read-only issues involved. :)
but is there any way to tackle the problem in JScript? 'cause i've java as my programming background, and i'm much more comfy using Jscript as my primary language in ASP.

glenngv
02-10-2003, 04:33 AM
I think you need to use the String constructor.
<%
...
var title, newStr;
title = new String(Request.Form("hTitle"));
newStr = title.concat("concatTest");
Response.Write("Keyed in Title is: " + newStr);
...
%>

Kinokunya
02-10-2003, 05:11 AM
woah glenngv YOU ARE a lifesaver!:eek:

thank you! :)

hmmz ... any roundabouts to do the same for retrieval of data from the database?

can i manipulate the String datatypes the same way using the newString( ) method as mentioned above?

i've remember reading somewhere in the text, that data returned from the RecordSet are treated as read-Only objects.

An option would be to close the connection from the database, alter the result sets, re-establish the connection to database back to update the latter, but when i closed the connection to the DB, they returned an error result saying that resultSet is no longer valid.

I know it may sound stupid in manner of my coding but ... *sigh*

whammy
02-11-2003, 02:02 AM
Like Glenn pointed out, since the data returned from a database apparently is a read-only object in JScript, you simply need to assign the result to a variable... :)

You can't manipulate the database variable itself unless you update the database anyway, that even applies to VBScript - so you need to store it in a "container" which would be a variable.

If you need to update the database itself, you'll need to use a SQL UPDATE statement.

glenngv
02-11-2003, 04:17 AM
any instance of a class inherits all the properties and methods of that class. You should know that, you are a Java man. :)
<%
...
var title, newStr;
title = new String(rsObj.Fields("hTitle"));
newStr = title.concat("concatTest");
Response.Write("Title is: " + newStr);
...
%>

whammy
02-11-2003, 04:25 AM
Heh, that looks more like it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum