none
0x800a138f - JavaScript runtime error: Unable to set property 'width' of undefined or null reference File

    Question

  • I'm navigating back and forth in my application and I get this error a number of times.

    It comes from default.js file.

    function button1Click(x,y,rowz,cols) {
            document.getElementById("circlecanvas").width = x;

    What should I do to prevent this error.

    I'm using RC.

    Saturday, November 10, 2012 11:56 PM

Answers

  • You got "Unable to set property 'width' of undefined or null.

    This means that the thing before .width was null/undefined

    Debug with:

    function buttion1Click(x,y,rowz,cols) {
      var circleCanvasEl = document.getElementById('circlecanvas');
      if (circleCanvasEl) {
        circleCanvasEl.width = x;
      } else {
        debugger;
      }

    One thing you may be doing is writing it in default.js before the app.onactivate event? Before the DOM was parsed by the browser - some libraries call this document.ready event. However the name of your event makes it seem like it was caused by someone clicking a button so maybe that's wrong...

    • Proposed as answer by Cobra Tap Sunday, November 11, 2012 5:45 PM
    • Marked as answer by Song TianModerator Friday, November 16, 2012 9:05 AM
    Sunday, November 11, 2012 5:45 PM

All replies

  • width property is under style property

    you can write it like this:

    document.getElementById("circlecanvas").style.width = x;

    Sunday, November 11, 2012 9:19 AM
  • You got "Unable to set property 'width' of undefined or null.

    This means that the thing before .width was null/undefined

    Debug with:

    function buttion1Click(x,y,rowz,cols) {
      var circleCanvasEl = document.getElementById('circlecanvas');
      if (circleCanvasEl) {
        circleCanvasEl.width = x;
      } else {
        debugger;
      }

    One thing you may be doing is writing it in default.js before the app.onactivate event? Before the DOM was parsed by the browser - some libraries call this document.ready event. However the name of your event makes it seem like it was caused by someone clicking a button so maybe that's wrong...

    • Proposed as answer by Cobra Tap Sunday, November 11, 2012 5:45 PM
    • Marked as answer by Song TianModerator Friday, November 16, 2012 9:05 AM
    Sunday, November 11, 2012 5:45 PM