Javascript setting variables and object and proper syntax (debug console)

So I am trying to invoke methods on a page and I know the values that I want to put inside the methods but I can't seem to get the syntax to work. I feel so, well.. lamerized. Ok so here is the javascript method on the page function ReturnValue (sValue, sText) { window.focus(); var oForm = document.EditForm; switch (szType) // Form element name { case 'agt': oForm.agt.value = sText; oForm.agentman.value = sValue; oForm.agtid.value = sValue; oForm.getagt.focus(); break; case 'county': oForm.County.value = sValue; sCurrentCounty = new String(sValue); document.all("CountyDisp").innerHTML = sText; document.all("City").value = ""; document.all("CityDisp").innerHTML = ""; document.all("Area").value = ""; document.all("AreaDisp").innerHTML = ""; break; default: break; } // End switch return; } Very straight forward function and you would assume that the parameters were strings, right? So in the IE8 Script Debugger Console I tried this: > ReturnValue("adf","asdf"); //FAIL "Object expected" Object expected huh, well maybe I need single quotes for the strings I assumed next (just in case). > ReturnValue('adf','asdf'); //FAIL "Object expected" Okay, just making sure.. So I need an object that stores a string. How about using a var I thought.. > var o = "adf"; var p = "dfsa"; ReturnValue(o,p); //FAIL "Object expected" I tried with single quotes just to be sure. So after all that I am sure an object is needed. So I tried to create an Object. > o = new Object(); k = new Object(); //{...} Now I from here I didn't know how to add a string to an object so I just did this. > o.value = "text"; k.value = "field"; // "text" ... "field" Okay so now I am feeling excited I have an object with some string in there so now I try to put it all together again. > ReturnValue(o,z) // EPIC FAIL "Object expected" I am putting Objects in there! Now I'm back to square one, can someone help? Okay problem still not solved. Upon further investigation I found that the script does infact run once at the very beginning of the page load. I can debug and break and while its paused through the code I can run the methods. But after I release and it finishes declaring all the variables I can't run any methods. But, for some reason the same method that I am trying to run is able to run from a Popup using the Window.Opener.ReturnValue(string,string); I dont get it! Javascript guru's where are you when I need you!
Ok I am still working on this and have had a break through. It turns out that if I type anything like Adfasdf() I'll get the same Error; For some reason the code isn't loading into the Console debugger. x_x I don't know why?

以上就是Javascript setting variables and object and proper syntax (debug console)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准