Page 1 of 1

Javascript variable problem

Posted: Thu Aug 03, 2006 2:02 am
by antubis
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello again.
Some days ago I posted a topic for a big grid. Because of very big traffic generation with PHP I decide to create it with JS. So .... 

[syntax="javascript"]

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

var container = document.getElementById('container');
var loop;

for(var loop = 1; loop <= 4048; loop++) {
    a = document.createElement('a');
    a.setAttribute('href', 'javascript:MM_showHideLayers(\'yourmsg\',\'\',\'hide\',\'msg\',\'\',\'hide\',\'newmsg\',\'\',\'show\',loop);');
    container.appendChild(a);

}
</script> 

IE generate this very fast. Maybe two or three seconds witch is very fast for such kind of big application. With PHP it takes me more than a minute ( to make the loop and to transfer the data )
I need to give to MM_showHideLayers() and the current number of the "a" element ( loop ).

Code: Select all

// This is not my code
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;

// This part is mine
document.getElementById('squire').value=args[9] }
}

I find this code over the web and it makes me good job. The problem is that document.getElementById('squire').value=args[9] don`t want to get the current element number, and the count of all elements. Exam - when u click on a part of the grid insted of serial number ( 1, 2 .. 5 .. 10 ), It shows the whole count + 1 ( 4049 ).

I`m not very good with JS so I may be wrong somewhere. Please, tell me where I`m wrong or how can I do this.

Thank you!


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Aug 07, 2006 10:32 am
by kendall
I cant help you much here...but from what your saying its problem maybe that your setting it after it has made a total count...you probably need to try and etract the exact value...maybe by using a eval() statement....again im not to knowledgable on JS maybe by putting it in eh for loop you may get the value u want but i dont know if that is what u want here

Kendall

Posted: Mon Aug 07, 2006 11:09 am
by volka
'javascript:MM_showHideLayers(\'yourmsg\',\'\',\'hide\',\'msg\',\'\',\'hide\',\'newmsg\',\'\',\'show\',loop);'
loop is not evaluated at this point - it's simply part of the string.
like

Code: Select all

<a href="javascript:showHideLayers(..., loop)
but not

Code: Select all

<a href="javascript:showHideLayers(..., 1)
<a href="javascript:showHideLayers(..., 2)
and so on
as intended.
And after for(var loop = 1; loop <= 4048; loop++) is done, loop is 4049