doforumda Posted August 26, 2011 Share Posted August 26, 2011 Hi all, I am making a t shirt website. I have about eight t-shirt thumbnails and these thumbnails are inside div tag with class 'thumbs'. Inside this thumbs div I have hidden input field as well. The value of thumbs div is the ID of the current thumbnail which taken from mysql database. Now what am I trying to do is when user clicks thumbs div tag then in javascript it should alert me the value of hidden input of this clicked thumbs div tag. Currently it displays only the first thumbnails hidden input value i.e. 1. SO How can I make this work so that when user clicks thumbs div tag, the value of that clicked thumbs' hidden input must be alerted? here is my code so far here is thumbs page <!DOCTYPE HTML> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="script/script.js"></script> <link type="text/css" rel="stylesheet" href="styles/styles.css" /> <title>title</title> </head> <body> <div id="left_menu"> <div id="tshirt_thumbs_container"> <?php if($rows) : ?> <?php foreach($rows as $r) : ?> <?php echo ""; ?> <?php echo "<div class='thumbs'>"; ?> <?php echo "<img src='" . $r->shirt_thumburl . "' />"; ?> <?php echo "<input type='hidden' id='thumbid' value='" . $r->shirtid . "' />"; ?> <?php echo "</div>"; ?> <!-- thumbs --> <?php endforeach; ?> <?php endif; ?> </div> </div><!-- left_menu --> <div id="contents"></div> </body> </html> here is .js file $(function(){ $('.thumbs').click(function() { var thisid = $(this + 'input[type="hidden"]').val(); //var thisid = $(this + " #thumbid").attr('id'); alert(thisid); }) }); please help Quote Link to comment https://forums.phpfreaks.com/topic/245739-need-help-getting-hidden-input-dynamic-value/ Share on other sites More sharing options...
voip03 Posted August 26, 2011 Share Posted August 26, 2011 you can develop from this code. <html> <head> <script type="text/javascript"> function validateForm() { var x=document.forms["imageUpload"]["thumbid"].value; alert(x); } </script> </head> <body> <?php $shirtid=5; // Demo Value only ?> <form name="imageUpload" action="#" onsubmit="return validateForm()" method="post"> <input type="hidden" name="thumbid" value="<? echo $shirtid; ?>" /> <input type="submit" value="Submit"> </form> </body> </html> PS. There is no need to declare ' <?php ...?>' in every line. One start and end will do. Quote Link to comment https://forums.phpfreaks.com/topic/245739-need-help-getting-hidden-input-dynamic-value/#findComment-1262156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.