Jump to content

Recommended Posts

Posted

When this code runs the browser running circle (in the tab display) never times out it just keeps running, why?

 

<head>

<script language="javascript" type="text/javascript">

 

function products_list() {

 

var products = new Array();

 

products[0] = "hair spray";

products[1] = "shoes";

products[2] = "flowers";

products[3] = "socks";

 

 

for (var i = 0; i < products.length; i++)

{

document.write(products + "<br>");

}

}

 

</script>

</head>

 

<body>

<h3 onclick="products_list()"> -> Show List</h3>

</body>

Posted

@grabenair:

You NEED to put a break in the code to stop or will keep going for ever and can cause problems.

Not quite true -- a for loop has an automatic break built in. In the code above, it should break after i is no longer less than products.length. (We're also dealing with Javascript here, not PHP.)

 

@Ed4Words:

When I run that code (and assuming I click on the header, obviously), the system prints out the four array items, then stops. As far as I can tell, it's working correctly. What is happening that makes you think the code is still running?

Posted (edited)

@grabenair:

 

Not quite true -- a for loop has an automatic break built in. In the code above, it should break after i is no longer less than products.length. (We're also dealing with Javascript here, not PHP.)

 

@Ed4Words:

When I run that code (and assuming I click on the header, obviously), the system prints out the four array items, then stops. As far as I can tell, it's working correctly. What is happening that makes you think the code is still running?

 

In the tab on my browser there is a running circle with the tab to the web page reading "connecting" and it doesn't seem to stop.

 

If I run the script in the body; then it loads with the page everything is normal, but of course the heading is over written.

But if I call the function which I named "products_list()" from the head with an "onclick" in the heading title, then I get a "connecting" message in the tab of the webpage that never seems to stop, although the web page does display the array values correctly.

Edited by Ed4words
Posted

@grabenair:

 

Not quite true -- a for loop has an automatic break built in. In the code above, it should break after i is no longer less than products.length. (We're also dealing with Javascript here, not PHP.)

 

@Ed4Words:

When I run that code (and assuming I click on the header, obviously), the system prints out the four array items, then stops. As far as I can tell, it's working correctly. What is happening that makes you think the code is still running?

 

Yeh, another strange thing - it does seem to work fine in my explorer 9 browser on my desktop, but the on running "connecting" message in the tab of the page is active in my Fire Fox browser on my laptop.

Strange??!

I always though of Monzilla as being javascript sensitive in there applications - that is they would be more prone to being bug free as far as running javascript.

 

Or maybe I have been hacked :bash:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...