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

.
.
.
.
.
ZWeberAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
monosodiumgConnect With a Mentor Commented:
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
 
brgivensCommented:
try this:

  splittemp=temp2.split(/:/);
0
 
ZWeberAuthor Commented:
No, this doesn't fix it.
Any other ideas, have you ever seen this before?


splittemp=temp2.split(/:/);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
brgivensCommented:
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
 
ZWeberAuthor Commented:
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
 
brgivensCommented:
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
 
monosodiumgCommented:
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
 
DanRollinsCommented:
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
 
ZWeberAuthor Commented:
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
 
ZWeberAuthor Commented:
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
 
brgivensCommented:
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
 
monosodiumgCommented:
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
 
ZWeberAuthor Commented:
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
 
brgivensConnect With a Mentor Commented:
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
 
ZWeberAuthor Commented:
Sorry I forgot to get back to this. Thanks for the help guys.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.