/    Sign up×
Community /Pin to ProfileBookmark

Simple Simple Stuff

var me;
var i=1;
function callit(){
me = eval(‘”ment” + i’);
document.me.style.width = 100;
}

Does anybody know why this doesn’t work?

Thanks

Lata

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [font=monospace]

var me, i = 1;

function callit(){

me = eval("ment"+i);

document.getElementById(me).style.width=100+"px";

}

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@David_HarrisonJul 23.2003 — I don't know how eval works really, I've never used it myself, but couldn't you just do this:

document.eval('"ment" + i').style.width = 100;

I [B]THINK[/B] the problem is that it's getting confused as to which variable to use, the variable outside the function, or the one inside.

What you could also do is remove the:

var me;

because if you don't use the var keyword in your functions to declare variables they are created as global variables.
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [font=arial][color=maroon]The code will actually work fine in IE (I used getElementById() for Netscape compatibility), if you add the "px" string to the end:[/color][/font]

[font=monospace]

document.me.style.width=100+"px";

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 23.2003 — Okay, hopefully I actually get to post this time. I don't know why but I'm having a really big problem with this forum.

Anyway, I suppose I could put it all in one but I did it like I did because it wouldn't work when I did it that way before and so I put that by itself and used the document.writln function to make sure it actually did what I wanted. So I know if I go document.writeln(me) it writes "ment1" which means that the variable me is defined as "ment1".

And that is the name for an image (right now that's just a test, I don't even have and image, just an area that I'm looking at to see if the coding works. When the code works then I'm going to apply to the id of divs so that I can do some cool stuff with them) so the image background should change from blue (that's what I have it at now) to red, but an error comes up saying that document.me is null or not an object.


Anybody have any ideas??????
Copy linkTweet thisAlerts:
@David_HarrisonJul 23.2003 — How's this for a change colour background, and no js involved:

[upl-file uuid=24123ba5-8303-4b1c-a6d1-32480a2aa62a size=550B]change colour background.txt[/upl-file]
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [font=monospace]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en-US">

<head><title>My Page</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Style-Type" content="text/css">

<meta name="Content-Script-Type" content="text/javascript">

<script type="text/javascript">

<!--

function edit(obj, specs){

eval("document.getElementById(obj).style."+specs);

}

//-->

</script>

<style type="text/css">

<!--

#myDiv { background-color:blue; }

-->

</style>

</head>

<body>

<div id="myDiv" onMouseOver="edit(this, 'backgroundColor='red'');">

Lorem ipsum solor dit amet

</div>

<form action="">

<input type="button" value="Turn blue" onClick="edit('myDiv', 'backgroundColor='blue'');"><br>

<input type="button" value="Turn red" onClick="edit('myDiv', 'backgroundColor='red'');">

</form>

</body>

</html>

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [font=arial][color=maroon]My code was escaped. The second internal strings should be ' not ' (around the backgroundColor='whatever=' not backgroundColor='whatever=')[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 23.2003 — Well, it's not really the colour I mean to change when I actually get the code to work. I just want to be able to call an element on the page like that so I can do anything with it, move it change the colour, size, whatever.


Thanks tho.
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [font=arial][color=maroon]Here's a text file with the [i]real[/i] code, because the forum keeps escaping my code.[/color][/font]

[b][J]ona[/b]

[upl-file uuid=f7465e01-e9e2-41e0-8c2b-aebe426c9cdf size=940B]changeobjprops.txt[/upl-file]
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [i]Originally posted by DJRobThaMan [/i]

[B]Well, it's not really the colour I mean to change when I actually get the code to work. I just want to be able to call an element on the page like that so I can do anything with it, move it change the colour, size, whatever. [/B][/QUOTE]


[font=arial][color=maroon]This code should help you get down that pathway.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 23.2003 — Thanks Jona. That last one really helped. Time to try messing with arrays now. Yay...
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [i]Originally posted by DJRobThaMan [/i]

[B]document.writeln function[/B][/QUOTE]


[font=arial][color=maroon]Just so you know, it's actually a method (which is like a function but it's attached to a specific object or type of object). In this case, it's a built-in method of the [b]document[/b] object.



Tell me if you need any help on those arrays. ?[/color]
[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 23.2003 — lol....


I stand corrected
Copy linkTweet thisAlerts:
@JonaJul 23.2003 — [i]Originally posted by DJRobThaMan [/i]

[B]I stand corrected [/B][/QUOTE]


[font=arial][color=maroon]I only meant to help. ?[/color][/font]

[b][J]ona[/b]
×

Success!

Help @DJRobThaMan 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.19,
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,
)...