Jump to content

need help getting hidden input dynamic value


doforumda

Recommended Posts

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

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.

Archived

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

×
×
  • 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.