Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I get "ReferenceError:'myreq' is undefined" error for <textarea> variable?

    Hi all;

    I have an ActiveX control that use it's functionality in a html file, so that I call it's methods and properties

    using a javascript function as below:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <style type="text/css">
    
    fieldset {
      border-color: #000;
      border-width: 3px;
      border-style: solid;
      padding: 10px;
      margin: 0;
      min-width: 400px;
      max-width: 800px;
      width: 800px; 
    }
    
    fieldset legend {
                color: blue
    	font-size: 1.1em; 
    }
    
    fieldset label:first-letter {
    	text-decoration: underline;   
    }
    
    input, textarea, select {
    	width: auto;
    	margin: 5px 0 0 10px;
    }
    
    .style1
    {
        width: 25%;
    }
    .style2
    {   
        color: #0000CC;
        font-weight: 700;
    }
    .style3
    {
        width: 213px;
    }
    </style>
    
    <script type="text/javascript">
    
    function OnGenReq()
    {
         
       var ret = MyOCX.GenerateReq(Text1.value, Text2.value, Text3.value, length1.value, Text4.value);
       document.getElementById("demo").innerHTML=ret;
    
       myreq.value = MyOCX.ReqString;
       //document.getElementById("myreq").value = MyOCX.ReqString;
       //document.getElementById("myreq").innerHTML = "teststring";
    
    }
    </script>
    </head>
    
    <body>
    <p id="demo"></p>
    <object id="MyOCX" width="0" height="0" codebase="C:\Users\Administrator\Documents\Activex.cab"
     classid="clsid:8F91127E-A84B-4FBD-AB43-AA63A63C0BE5">
        <param name="_Version" value="65536">
        <param name="_ExtentX" value="2646">
        <param name="_ExtentY" value="1323">
        <param name="_StockProps" value="0">
    </object>
    <p></p>
    
    <fieldset>
    <legend class="style2">Generate Request:</legend>
    
    <label for="Text1">First string Arg:</label><input id="Text1" type="text"><br>
    <label for="Text2">Second string Arg:</label><input id="Text2" type="text"><br>
    <label for="Text3">Third string Arg:</label><input id="Text3" type="text"><br>
    <label for="length1">Length value:</label> 
    <select id="length1"> 
      <option selected="selected" value="100">100</option>
      <option value="200">200</option>
      <option value="300">300</option>
    </select><br>
    <label for="Text4">Forth string Arg:</label><input id="Text4" size="30" type="text"><br><br>
    
    <label for="gen"></label><input id="gen" value="Generate Request" type="button" onclick="try{OnGenReq()}catch(e)
    
    {alert(e)}"><br><br>
    <center> 
    <label for="myreq">Req String</label><br><textarea id="myreq" rows="15" cols="66"></textarea><br><br>
    </center>
    </fieldset>
    
    </body>
    </html>
    As you see in the html code, I have a <textarea> tag with "myreq" id that want to display "ReqString" value (that

    is a custom property of the activex) into textarea.

    When I click "Generate Request" button, "MyOCX.GenerateReq" method runs to assign a string value to "ReqString"

    property. But when I assign "MyOCX.ReqString" value to "myreq" to be displayed in the textarea using either:

    myreq.value = MyOCX.ReqString;

    OR

    document.getElementById("myreq").value = MyOCX.ReqString;

    I get the error "ReferenceError:'myreq' is undefined", while "myreq" is defined within the <fieldset> tag!

    Could you tell me what's wrong with this code?

    TIA.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Well, if you reduce the page down to JUST THIS:
    Code:
    <html>
    <body>
    <p id="demo"></p>
    <p></p>
    
    <fieldset>
    <legend class="style2">Generate Request:</legend>
    
    <label for="Text1">First string Arg:</label><input id="Text1" type="text"><br>
    <label for="Text2">Second string Arg:</label><input id="Text2" type="text"><br>
    <label for="Text3">Third string Arg:</label><input id="Text3" type="text"><br>
    <label for="length1">Length value:</label> 
    <select id="length1"> 
      <option selected="selected" value="100">100</option>
      <option value="200">200</option>
      <option value="300">300</option>
    </select><br>
    <label for="Text4">Forth string Arg:</label><input id="Text4" size="30" type="text"><br><br>
    
    <label for="gen"></label><input id="gen" value="Generate Request" type="button" onclick="try{OnGenReq()}
    
    catch(e)
    
    {alert(e)}"><br><br>
    <center> 
    <label for="myreq">Req String</label><br><textarea id="myreq" rows="15" cols="66"></textarea><br><br>
    </center>
    </fieldset>
    
    <script type="text/javascript">
    document.getElementById("myreq").value="Zambonis Rule!\nReally.";
    function OnGenReq()
    {
       document.getElementById("myreq").value = "Should work";
    }
    </script>
    </body>
    </html>
    You can see that indeed the getElementById version works (twice).

    So... One has to wonder if the OCX control is somehow causing an error???

    I dunno.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •