I have this code:

    <?php foreach ($_options as $_option) : ?>
    <input id="xyys" type="hidden" name="xyys" value="<?php echo($_option['value']);echo ($_option['option_id']);?>" /> 


            <?php if($_option['label'] != 'Corte'): ?>

                <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
                <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>><?php echo $_formatedOptionValue['value'] ?>
                    <?php if (isset($_formatedOptionValue['full_view'])): ?>
                    <div class="truncated_full_value">
                        <dl class="item-options">
                            <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                            <dd><?php echo $_formatedOptionValue['full_view'] ?></dd>
                        </dl>
                    </div>
                    <?php endif; ?>
                </dd>
            <?php else: ?>
                <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
                <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>





                <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>>

                <img id="fotop" name="fotop" height="100px" width="100px" src=""></img><?php echo Si; ?>


                    <?php if (isset($_formatedOptionValue['full_view'])): ?>
                    <div class="truncated_full_value">
                        <dl class="item-options">
                            <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                            <dd><img id="fotog" name="fotop" src=""></img><?php echo Si; ?></dd>
                        </dl>
                    </div>




                    <?php endif; ?>
                </dd>
            <?php endif;?>

            <script type="text/javascript">


                var hero;
                if ( localStorage.getItem('xyys')) {
                hero = localStorage.getItem('xyys');
                }
                else {
                hero = '/MvV336/rn67r8+/DbWa7b+G/gqh8H4Tw2ReXw3P5Muav3fFfjz+vze9nzdEouli5fwlnlcrlyMuXnye8eHM7/pzYznGXvof1T9u6ziLvD6H9U/bukIfQ/qn7d0hD6H9U/bukI+D6nw/8o8fL7d/q+XSODH36H9U/bukcw+h/VP27pCH0P6p+3dIQ+h/VP27pCH0P6p+3dIQ+h/VP27pCH0P6p+3dIR//9k='; 
                localStorage.setItem('xyys',hero);
                }

                document.getElementById("fotop").src=hero;
                document.getElementById("fotog").src=hero;
                </script>

                <?php echo ("hi!");?>
        <?php endforeach; ?>

Basically Im trying to run a Javascript each time in the for each....

I know it runs thru it because "hi!" is shown but it only executes the Javascript once.

i want it to execute it during each run in the foreach. Why doesnt it do it?

are you sure it runs only once? Have you tried alert('somethin') in it? does it also runs only once? if not, maybe there is trouble in something else

Hi
JavaScript is executed in browser after php otput the code.
The for each in php probably adds multiple Script tag with the same JS code, see in the source page.

are you sure it runs only once? Have you tried alert('somethin') in it? does it also runs only once? if not, maybe there is trouble in something else

I explained incorrectly. I apoligize.

The code runs thru all the times neccesary but only does what it needs to do once. In this case

document.getElementById("fotop").src=hero;

Hi
JavaScript is executed in browser after php otput the code.
The for each in php probably adds multiple Script tag with the same JS code, see in the source page.

This isnt a problem. Other than speed problems, this shouldnt cause anything else.

> document.getElementById("fotop").src=hero;
>     document.getElementById("fotog").src=hero;

this set source attribute value I guess, rigth? Try remove one of the lines, which work. what happens then? Does another line start to work if one is removed?