Jump to content

Archived

This topic is now archived and is closed to further replies.

Kris

Problem mixing PHP and JavaScript to submit dynamicaly created forms.

Recommended Posts

I have a list of thumbnail images in a scrolling div, that when clicked, I'd like the large version of the image to load up in another div - I don't want to be passing stuff through the URL so I'm dynamicaly creating forms with the relevent information in hidden fields and submitting it back to itself. Now, it's only working when clicking on the last displayed thumbnail - When clicking on any other thumbnail the FireFox JavaScript debugger is giving me 'document.load_face_16 has no properties' messages (the '16' part varies depending on what image/form was submitted).

[code]<div style="overflow:scroll; overflow-x:hidden; height:450px; width:150px; border:1px solid #000; text-align:center;">
    <?php
    $result = mysql_query("SELECT p.`name`, pf.`id`
    FROM `product` as p, `product_face` as pf
    WHERE p.`id` = pf.`product_id` AND pf.`default` = '1'
    ORDER BY `name` DESC") or die(mysql_error());
    while($row = mysql_fetch_assoc($result)) {
        echo "<form name='load_face_$row[id]' action='' method='post'><input type='hidden' name='product_face_id' value='$row[id]'/></form>
        <img src='../images/product/face/$row[id]_thumb_l.jpg' alt='$row[name]' border='0px' style='padding-bottom:6px;' onclick='document.load_face_$row[id].submit();'/><br/>";
    }
    ?>
</div>[/code]

Considering the last one works, is the last one overwriting something defined in all of the previous ones? Any help is greatly appreciated :)

Share this post


Link to post
Share on other sites
try

onclick='document.forms[{document.load_face_$row[id]}].submit();'

or possibly without the { } i haven't quite worked out the whole {} part but i think in some browsers you can't just use the form.formname you have to use document.forms[formname] or document.getelementbyid[formname] (with id='formname' in your form tags)

Share this post


Link to post
Share on other sites
Hmmm, thanks Crayon, I'll try that out when I get back in the office. Although, I did try document.forms.load_face_$row[id].submit(); which is similar but there's still a difference. I'll report back once I have tried it.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.