www.webdeveloper.com
Results 1 to 7 of 7

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

  1. #1
    Join Date
    Jun 2012
    Posts
    8

    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. #2
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    When I looked up the textarea tag in some of my references I don't see a value property. I think you may be running into an issue because of this. It is a block area who's 'value' is between the tags. But I see you have a similar line commented out, so what is the deal there? Does it work with innerHTML?

    Edit: Also in the code above that

    Code:
    myreq.value = MyOCX.ReqString;
       //document.getElementById("myreq").value = MyOCX.ReqString;
       //document.getElementById("myreq").innerHTML = "teststring";
    When is myreq defined? If its in the document you would have to ref the document as well.
    Last edited by burnme; 07-19-2012 at 03:07 PM.

  3. #3
    Join Date
    Jun 2012
    Posts
    8
    Quote Originally Posted by burnme View Post
    When I looked up the textarea tag in some of my references I don't see a value property. I think you may be running into an issue because of this. It is a block area who's 'value' is between the tags. But I see you have a similar line commented out, so what is the deal there? Does it work with innerHTML?

    Edit: Also in the code above that

    Code:
    myreq.value = MyOCX.ReqString;
       //document.getElementById("myreq").value = MyOCX.ReqString;
       //document.getElementById("myreq").innerHTML = "teststring";
    When is myreq defined? If its in the document you would have to ref the document as well.
    Dear burnme, thanks for the reply.

    No, It displays the same error with innerHTML!
    I think, make a mistake in textarea (myreq) definition.
    It is defined as below:
    <label for="myreq">Req String</label><br><textarea id="myreq" rows="15" cols="66"></textarea><br><br>

    I don't know which line of code should I modify for this error?

  4. #4
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Okay, here is the deal, I took out all your OCX code and it works just fine, SO something is happening with that. That's the best I can say, I don't have access to your OCX, but it has to be that. Here is the code I used, with the stuff taken out. If you want help on the OCX code, I am well versed in MANY other languages, so it you have somewhere you want to put it, I would be happy to help you out there.

    Edit: I would copy and paste this into a test.html file and run it, I just put crap in the boxes, but all is well without the ocx parts.

    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&#37;;
    }
    .style2
    {   
        color: #0000CC;
        font-weight: 700;
    }
    .style3
    {
        width: 213px;
    }
    </style>
    
    <script type="text/javascript">
    
    function OnGenReq()
    {
    
        //myreq.value = "blah";
       document.getElementById("myreq").value = "987654";
       //document.getElementById("myreq").innerHTML = "teststring";
    
    }
    </script>
    </head>
    
    <body>
    
    <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>

  5. #5
    Join Date
    Jun 2012
    Posts
    8
    Thanks burnme;

    The problem is resolved!
    It was because of adding some lines to display the function's return value in the document.

    Now, I have another question please!!

    As you know, we don't have Array type property in MFC ActiveX control (I'm using Visual C++ 2008) and I don't have any experience in using VARIANT type.

    In another function of my activex, I want to assign an array of strings (of type CStringArray) to a custom array property and then, get and parse this string array (property returned from activex) in javascript code to show all of these strings in a list at html page.

    I have no idea that how should I do this work?
    I've searched so much, but didn't find any working solution!

    Could you help me again about this?!

    Thanks a lot.

  6. #6
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Well I guess I don't quite get the question but I may have an idea of what you are talking about. If I am correct about what you need, I think you could simply do .toString on your array in the ocx, so it is one big chunk of characters with a delimiter i.e. comma, pipe, or whatever, then simply have javascript do a split on the values. I personally don't like to do to much 'special' stuff when passing from one language/platform to another, too much can go wrong, but characters are almost always cheap and easy. Take a look at this pages, do the same thing you did with the function I have already worked with, by passing out the info you want like "myval1,myval2,myval3,myval4", then in your javascript just:

    Code:
    function GiveMeMyStuff(mystuff){
    var n = mystuff.split(",");
    var blah = n[0]; //which is myval1 and so on, just the same as most any language
    }
    http://www.w3schools.com/jsref/jsref_obj_string.asp
    http://www.w3schools.com/jsref/jsref_split.asp

  7. #7
    Join Date
    Jun 2012
    Posts
    8
    Thanks again.

    Your post was so helpful;

    Thus, I've written my problem precisely at one of MSDN forums that is here:
    Code:
    http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/db39fe66-8fb7-488c-af95-ace29dd0567e?prof=required
    Have you any suggestion to do this work please?

    If you would like to reply here or over there, I'll greatly appreciate you.

    Regards.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles