Solved

split method acting weirdly, passing identical value, faults one way but not the other, I'm going insane.

Posted on 2004-04-11
16
524 Views
Last Modified: 2012-05-04
I'm getting the following error:

>>>
Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn't support this property or method
@ line 36
>>>>


with the following code. If I force the temp2 var to the value it already is, it works. If I remove this line the next line give the error message. I'm out of ideas, can anyone help??


function FormSetCycle(){
  for (j=1; j<FieldLabels.length; ++j){
     temp=FieldLabels[j];
     temp2=TargetDBTable+"Z"+temp+"Z"+i;
     temp2=(Request.Form(temp2));
     if(!isNaN(parseInt(temp2))){
        temp2=parseInt(temp2);
     };

     if(temp=="FKey"){
         if(isNaN(temp2)){
      
             Response.Write(temp2=="new:1");// << Proves that temp2 =="new:1"
      temp2="new:1"; //<<<<<<<<<<<<<< Without this line the next line faults out.

            splittemp=temp2.split(":"); // Problem line.....
            Response.Write(" [0] ="+splittemp[0]);
            Response.Write(" [1] ="+splittemp[1]);

.
.
.
.
.
0
Comment
Question by:ZWeber
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 7

Expert Comment

by:brgivens
ID: 10801149
try this:

  splittemp=temp2.split(/:/);
0
 

Author Comment

by:ZWeber
ID: 10801155
No, this doesn't fix it.
Any other ideas, have you ever seen this before?


splittemp=temp2.split(/:/);
0
 
LVL 7

Expert Comment

by:brgivens
ID: 10801172
No, I can't say I've seen anything like this b4

As a test, try this:

Response.Write Request.Form(TargetDBTable+"Z"+temp+"Z"+i).split(/:/);
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:ZWeber
ID: 10801213
That works. But not with temp2.

BTW, I might be running out of time for this session, being Easter and all, if you don't hear back from me I'll be back at it tonight. Thanks for your help.
0
 
LVL 7

Expert Comment

by:brgivens
ID: 10801367
function FormSetCycle(){
  for (j=1; j<FieldLabels.length; ++j){
     var s=TargetDBTable+"Z"+FieldLabels[j]+"Z"+i, t=Request.Form(s);
     if(!isNaN(parseInt(t))) t=parseInt(t);
     if(FieldLabels[j]=="FKey"){
         if(isNaN(t)){
          var a=t.split(/:/);
//          var a=Request.Form(s).split(/:/);  // use this only if the preceeding line doesn't work
          Response.Write(" [0] ="+a[0]);
          Response.Write(" [1] ="+a[1]);
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 10801523
The reason I think is that Request.Form(temp2) is NOT the value of the temp2 field. It is in fact a reference to the temp2 field.
The default property of a form fields reference is "Value", which is why
Response.Write(temp2=="new:1") works.
That line is actually being treated as:
Response.Write(temp2.value=="new:1")

When the interpreter hits the problem line:
temp2.split(":")
it can't find a "split" method for the form field object temp2.

If you want the Value of a field, always use:
Request.Form(temp2).Value

The result of that is a string, not a form field reference. The rest of the code should then work.


BTW, using "temp2" first as the name of the field and then as the field (or it's value) is not nice. Reusing your variables like taht won't work in proper languages (vbscript it the programming equivalent of grunting ;) and it makes code harder to read.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10802470
I agree with  monosodiumg.  I've seen the same behavior many times.  If you rely on that "default conversion to string," you will get off the track into the land of inexplicable errors :-)  -- Dan
0
 

Author Comment

by:ZWeber
ID: 10803286
brgivens, no go on both suggestions.

monosodiumg, I really liked your explanation and I was very hopefull, but unfortunately it didn't work either." Request.Form(temp2).Value" returns as "undefined".
Is there another way to convert from a ref. to a value.

Do you have any other suggestions?
Thanks for the help guys.
0
 

Author Comment

by:ZWeber
ID: 10803309
monosodiumg, concerning your BTW. You are right. I cut my teeth on machine code in embedded controllers when var space was scarce, and havn't done a lot of coding since . Old habits die hard.
0
 
LVL 7

Expert Comment

by:brgivens
ID: 10803310
A couple of points:

Request.Form("whatever") returns either a string or Null, it does not return an object.

Request.Form("whatever").Value will generate an error.

I'm really surprised that neither of the suggestions I posted didn't work.  Maybe it's because the Request.FOrm is null?

function FormSetCycle(){
  for (j=1; j<FieldLabels.length; ++j){
     var s=TargetDBTable+"Z"+FieldLabels[j]+"Z"+i, t=Request.Form(s);
     if(t!=null) {
       if(!isNaN(parseInt(t))) t=parseInt(t);
       if(FieldLabels[j]=="FKey"){
           if(isNaN(t)){
            var a=t.split(/:/);
//            var a=Request.Form(s).split(/:/);  // use this only if the preceeding line doesn't work
            Response.Write(" [0] ="+a[0]);
            Response.Write(" [1] ="+a[1]);
        ...
      }
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 10804801
brgivens is right about the ".Value" being wrong. I'm getting my languages mixed up.

What does Request.Form("temp2") return?

Check the reference on Request.Form: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_vbom_reqocf.asp
0
 

Author Comment

by:ZWeber
ID: 10806473
I've confirmed that 'temp2' is returning a value and is not null.  The split. works if I reset temp2 to the value it should already be. I know this by comparing the temp2 value with the value I'm about to resetr it to. This test returns true. I then reset the temp2 and the split. works.  I've also read thru the MS ref, but didn't gain any insight. I'm stumped.
0
 
LVL 12

Accepted Solution

by:
monosodiumg earned 250 total points
ID: 10808966
My point about the type of Request.Form("foo") not being string is right:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;173317

It's olnly in javascript you need the ".value". In JScript you need to cast to String, as someone else with a similar problem discovered:
http://dbforums.com/arch/192/2002/7/424163

0
 
LVL 7

Assisted Solution

by:brgivens
brgivens earned 250 total points
ID: 10809114
mg,

I stand corrected... good to know!

From that link you provided, the solution to try would be:

function FormSetCycle(){
  for (j=1; j<FieldLabels.length; ++j){
     var s=TargetDBTable+"Z"+FieldLabels[j]+"Z"+i, t=Request.Form(s).item;
     if(!isNaN(parseInt(t))) t=parseInt(t);
     if(FieldLabels[j]=="FKey"){
         if(isNaN(t)){
          var a=t.split(/:/);
          Response.Write(" [0] ="+a[0]);
          Response.Write(" [1] ="+a[1]);
0
 

Author Comment

by:ZWeber
ID: 11077900
Sorry I forgot to get back to this. Thanks for the help guys.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question