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 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,873
    Thanks
    31
    Thanked 4 Times in 4 Posts

    My basic onClick="wrapText(document.getElementById)" is not working

    After some hours of looking at this,
    I have to ask ...

    I have two web sites - one with the "Editor" function working and my new site
    where the same scripting just won't work

    It isn't any difficult javascript - just the onClick function

    My basic onClick="wrapText(document.getElementById)" is not working

    I have nice little Editor strip with buttons that should wrap any highlighted text
    in BBCode

    EG.
    Code:
    <img class="imgbtn" src="/sys_images/bold.gif" width="21" height="20" alt="Bold" title="Bold" onClick="wrapText(document.getElementById('BodyText'),'[stg]','[/stg]');">
    It's probably easier to view the code from the source code on the url:

    https://premhomes.org/edit-blog-art.php?a=1

    -a_site-prob01.jpg

    If anyone can see why the simple onClick isn't working, I'd be eternally thankful

    David.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  2. #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,962
    Thanks
    58
    Thanked 709 Times in 704 Posts
    I get an error in the console saying that wrapText is not defined and I can't find that function anywhere - have you forgotten to include a .js file maybe?

  3. #3
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,571
    Thanks
    5
    Thanked 517 Times in 504 Posts
    Yeah, what's "wrapText"?

    Not that your page is much help with the layout being utterly banjaxed, everything crammed into a narrow ~10em or so width column on the right.

    Is it supposed to look like this, or is it falling apart from mxing-matching EM/REM with Pixels?

    https://cutcodedown.com/for_others/j...ges/broken.png

    Though it STILL has all the same shortcomings / broken code as last time I looked at it; just this time you're adding more JavaScript to do things that are none of JS' business. Well, along with STYLE="" on non-style (except in Chrome, which is WRONG and violating the spec) elements like OPTION... oh, I see, trying to make an editor.

    Good luck on that. You're diving into JS before you're done learning HTML. Two tips:

    1) if it's JavaScript "only", the element itself doesn't belong in the markup.

    2) 99.99% of the time you see an onevent attribute in the markup, the code is more 1997 than 2019. Either attach the event to the existing element from the script, or since said element has NO business in the markup, create the DOM element and then attach the event to it BEFORE you even put it on the live DOM.

    To be brutally frank, all those IMG tags? ZERO business in the markup, ZERO business as separate image files if you care about decent load times, ZERO business using onclick. You're writing markup that shouldn't even exist, and likely twice or more the scripting needed as well.
    Last edited by deathshadow; Jul 13th, 2019 at 05:49 AM.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com


 

Tags for this Thread

Posting Permissions

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