Jump to content


Photo

Problem mixing PHP and JavaScript to submit dynamicaly created forms.


  • Please log in to reply
2 replies to this topic

#1 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 21 September 2006 - 05:18 PM

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).

<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>

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 September 2006 - 05:38 PM

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)
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 21 September 2006 - 08:29 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users