Link to home
Start Free TrialLog in
Avatar of ZWeber
ZWeber

asked on

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

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]);

.
.
.
.
.
Avatar of brgivens
brgivens

try this:

  splittemp=temp2.split(/:/);
Avatar of ZWeber

ASKER

No, this doesn't fix it.
Any other ideas, have you ever seen this before?


splittemp=temp2.split(/:/);
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(/:/);
Avatar of ZWeber

ASKER

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

Avatar of DanRollins
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
Avatar of ZWeber

ASKER

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.
Avatar of ZWeber

ASKER

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.
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]);
        ...
      }
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
Avatar of ZWeber

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of monosodiumg
monosodiumg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZWeber

ASKER

Sorry I forgot to get back to this. Thanks for the help guys.