1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Crazy Unknown RunTime Error! Help!

Discussion in 'JavaScript' started by mdvasanth86, Mar 11, 2014.

  1. #1
    Hi DP users,

    I'm struggling to figure this out since two days.. No luck... I need some help.


    The error that I am getting if it is of any use:

    -********************************************************************-
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
    Timestamp: Wed, 12 Mar 2014 01:36:11 UTC


    Message: Unknown runtime error
    Line: 54
    Char: 3
    Code: 0
    URI: file:///C:/Users/dvasa/Desktop/RE_USE/Compliance/Final.html

    --********************************************************************-

    I'm basically trying to write some HTML text with Images tags et all to a TextArea.

    This is my form:

    <form name="lazForm">

    <input type="hidden" name="piced">
    <button onclick="picFunction()">PiC-It!!!</button><br>
    <textarea rows="2" cols="20" name="truarea"></textarea>

    This is part of my script:

    function picFunction()
    {

    var lazdata = window.parent.Decrypt.document.myForm.realacc.value;
    var k;
    var a;
    var tab1 , tab2 ;
    tab1 = '<img src = "C:\Users\dvasa.png">';
    ............
    ............
    ............
    }



    If (<Something>)
    {
    document.getElementById( "truarea" ).innerHTML += tab1;

    }


    Is there any fix for this? IE gives no clues as to what the error is..

    BTW, I'm totally new to Javascript or any other scripting for that matter. I'm actually into Mainframes. So, please excuse me if this is a silly Question.

    Thanks!
     
    Solved! View solution.
    mdvasanth86, Mar 11, 2014 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Looks like you got some bad or outdated advice... as a rule of thumb you shouldn't be using innerHTML any time after 1998... of course NOBODY seems to have paid attention to that no matter how many times it bites you in the backside.

    But your big problem is you are using getElementById... without a matching ID... you have a NAME declared, but NAME isn't for manipulating values in javascript unless you are still writing Nyetscape 4 style scripting.

    To use getElementById you have to have an ID on the element...

    <textarea rows="2" cols="20" name="truarea" id="truarea"></textarea>

    NAME is for what's sent to the server, ID is for targeting with href="#", javascript or CSS. Sadly a distinction a lot of "experienced" developers don't even understand...

    Then you should be using the element's VALUE attribute, thus:
    document.getElementById('truarea').value += tab1;

    Also, don't try to use IE for... uhm... anything in terms of script debugging. The error console in 'real' Opera (12.16, as opposed to the new pathetic crippleware known as Chrome with the Opera logo slapped on it) and Firefox (I usually use both) will give you far more relevant error messages, much less the tools 'firebug' (an FF extension) and Dragonfly (built into Opera) which will let you trace into your code.
     
    deathshadow, Mar 11, 2014 IP
  3. mdvasanth86

    mdvasanth86 Notable Member

    Messages:
    3,869
    Likes Received:
    285
    Best Answers:
    0
    Trophy Points:
    230
    #3
    Hi deathshadow,
    Yes I noticed the Id thing and fixed it.
    The issue still persists.

    I am a Firefox fan as well. But never used it for this. I will start using it as you have suggested.

    From what I have seen the issue is with the url parsing. I guess it's getting confused with the / , ', ", < , > signs in the url. Should we use something like the escape characters used in SQL for % and _ ???

    Thanks
     
    mdvasanth86, Mar 12, 2014 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Using .value it shouldn't matter. Using innerHTML you would have to do the equivalent of PHP's htmlspecialchars on it. replacing at the very least brackets with their HTML entities like &gt; &lt; &amp; and so forth.

    Lemme make a quick test-case and get back to you -- usually I don't plug markup into a textarea.
     
    deathshadow, Mar 12, 2014 IP
  5. #5
    I got it not making any errors, but found another bug. You are using button -- buttons are effectively input type="submit"... so it's submitting when you click "pic-it", which I'm pretty sure you don't want.

    Remember when you use the outdated/outmoded 'onclick' you have to include 'return false'... unless submitting it was your intent.
    <button onclick="picFunction(); return false;">PiC-It!!!</button>

    Though it would be better if that button was added by the script with the method on it already, using cancelEvent/cancelBubble methodology to prevent the cascade, that way scripting off you aren't showing non-functional elements.... since again, the unwritten rule of javascript is "If you can't make a page that works without JavaScript FIRST, you have no business adding JavaScript to it."

    The translation to % entities should happen automatically when you submit. You'll have to decode that server-side since again, getData is ALWAYS formatted that way. Usually though if you have a textarea you shouldn't be using GET in the first place since it has size limits. It's not exactly URI friendly.
     
    deathshadow, Mar 12, 2014 IP
  6. mdvasanth86

    mdvasanth86 Notable Member

    Messages:
    3,869
    Likes Received:
    285
    Best Answers:
    0
    Trophy Points:
    230
    #6
    It worked deathshadow.... Appreciate your time. Thank you!
     
    mdvasanth86, Mar 15, 2014 IP