javascript problem - probably very simple

Associate
Joined
24 Jul 2004
Posts
1,580
Location
Preston, Lancs
ok, so i have a pretty decent understanding of php but am in need of some jquery based elements in my script (an image cropper).

so, in php I would do something like this:

PHP:
for($x=0;$x<10;$x++)
{
       echo '<input type="hidden" name="ft_'.$x.'" id="ft_'.$x.'" value="1">';
       echo '<input type="hidden" name="fl_'.$x.'" id="fl_'.$x.'" value="1">';
}

The equivalent javascript - in my head - would be this:

Code:
for($x=0;$x<10;$x++)
{
                    Dom.setAttribute('ft_'+ x.toString(), 'value', region.top);
                    Dom.setAttribute('fl_'+ x.toString(), 'value', region.left);
}

but this doesn't work...

I'm struggling to find good javascript resources and dont really have time to wait for an amazon book. Tizag / w3schools are my php helpers of choice, but the Javascript stuff isn't brilliant.

Any pointers would be most appreciated. :confused:
 
aye - i guess this is one of those probs where it's hard to explain but seems like it should be basic in my head.

Found a horribly hacky way of doing it:

Code:
                    Dom.get('t_<?php echo $x; ?>').innerHTML = region.top;
                    Dom.get('l_<?php echo $x; ?>').innerHTML = region.left;
                    Dom.get('h_<?php echo $x; ?>').innerHTML = region.height;
                    Dom.get('w_<?php echo $x; ?>').innerHTML = region.width;

not there yet, but closer.
 
cheers - and thanks for the examples, very helpful - much easier to understand when you can see the code and outcome.

I have this code almost finished actually, the strange thing is - it works fine when statically coded, but when php generates the exact same code, it doesnt work as intended.

Bugs, gotta love em.
 
Back
Top Bottom