/    Sign up×
Community /Pin to ProfileBookmark

Why can’t I use eval()?

Hello, I am a webcomic artist and web designer-in-training. My question is why can’t I use eval() for a basic slideshow? The code I am using as a guideline for my own is simple and to the point. All I want is a basic, clickable slideshow that can showcase the pages of my series. My problem is I have come across sites that are against the use of eval(). Some even going as far to say it is deprecated. The code works fine when I preview it in the browser and so far, everything works as it should. I have an important event coming up that could bring some much needed exposure for the series, and it would be detrimental if an error were to occur and my work not be displayed. If the string: eval(“img”+order+”.src”) is wrong, what should I use instead?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@thechasboiSep 17.2007 — redflame3

It seems that you are trying to replace the source of the image tag. If so you need to do something like this
[CODE]
var imageSRC = new Image();
imageSRC = '/images/blahblah.jpg';
if(document.getElementById('imgID')){if(imageSRC != ''){document.getElementById('imgID').src=imageSRC}}
[/CODE]

This should be what you need to replace the source of the image. You could also try to replace the innHTML of the element the image is in with a new img tag with all the needed data. Hope that helps and gives you ideas. Good luck if it does.
Copy linkTweet thisAlerts:
@felgallSep 17.2007 — There are two problems with using eval()

  • 1. It is one of the two least efficient commands in Javascript and therefore chews up far more resources thn a better coded alternative would use.


  • 2. Unless you carefully validate the content of the call before making it the visitors to your page can add their own code into the content and run anything they like in your web page.
  • ×

    Success!

    Help @redflame3 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...