/    Sign up×
Community /Pin to ProfileBookmark

JavaScript works only with ALERT box!

Hello everyone. I’m new here to the forums and have a quick question about some JavaScript code I’m working on.

In IE, I’m trying to display a resized image to the screen. I recalculate the size by setting iHeight and iWidth. The strange thing is that this code only works if I put an alert on the screen.

alert (“testing”);
$iHeight = 150;
$iWidth = 300;
// This resizes perfectly.

If I have the above code WITHOUT the alert box code, it doesn’t work!! It’s almost as if JavaScript just skips right over the code.

Any suggestions? This is really driving me nuts!!

Thanks MUCH in advance!!!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@cyber1Sep 17.2005 — 
If I have the above code WITHOUT the alert box code, it doesn't work!! It's almost as if JavaScript just skips right over the code.

Any suggestions? This is really driving me nuts!!

Thanks MUCH in advance!!![/QUOTE]


JS does not use $ to indicate variables.

alert ("testing");

$iHeight = 150;

$iWidth = 300;

should be:

var iHeight = 150;

var iWidth = 300;

alert ("testing ... iHeight:"+iHeight+"iWidth:"+iWidth);

-Bill
Copy linkTweet thisAlerts:
@eric1969authorSep 17.2005 — You're right, Bill! Sorry about that. I'm so used to programming in php that I mis-typed my code.

The actual JavaScript code does not have the '$' before the variables.
Copy linkTweet thisAlerts:
@felgallSep 17.2005 — Actually $ is a valid character to use in Javascript variable names.

To work out why the code is not working will require seeing more of the actual code since the problem is not with the small part that you have posted so far.
Copy linkTweet thisAlerts:
@DaRocknessJun 14.2008 — Yeah I'm running into a similar problem; it appears that there is some sort of stop execution of thread; which is defined in the alert function...

Currently I am writting pure javascript HTTP request; with no AJAX support. (I don't like using ActiveX components EVER) in my code there is a while loop; and the while loop is rendering an element to screen and some text while it waits for an aSync response from the server.

If I run the code normally; the page locks up and says "Not Responding" at the title of the page; however, prior to execution of the loop if I place an alert box (for error debuging) the code works fine.

My guess is that the "alert" function is actually forcing some sort of cleanup or doevents code which allows the code to execute correctly. I was wondering if anyone had the logic for the Alert function itself so I can figure out away to not interrupt the code to have execution of the code. It's intended to be seamless.
Copy linkTweet thisAlerts:
@DaRocknessJun 14.2008 — Well to answer my own question I think I figured out what the problem was.

Before execution of the loop I am createing an element. which I access in the while loop...

This element needs time to render to the screen, otherwise it doesn't exist technically.

I think the alert box gives the document enough time to render the element.
Copy linkTweet thisAlerts:
@Declan1991Jun 14.2008 — Just by the way, ActiveX only needs to be used in JavaScript in IE6 and less. To fix that, either call the JavaScript after the element:[code=html]<div>
</div>
<script type="text/javascript">
startFn();
</script>
[/code]
or using window.onload.
Copy linkTweet thisAlerts:
@DaRocknessJun 16.2008 — Yeah I knew that, my problem revolves around the "AJAX" implementation of XML / HTTP get / posting.

I solved it, and have create a pure Javascript implementation which does not require AJAX or any ActiveX components.

If anyone ever tells you you cannot do Javascript HTTP/XML handling without AJAX they are completely wrong. You just need to know somethings about client/server development and some knowledge of PHP.

"Never fear ------- is here!" <- fill in the blank!
×

Success!

Help @eric1969 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.17,
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,
)...