Jump to content

Problem mixing PHP and JavaScript to submit dynamicaly created forms.


zq29

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 :)
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.