0

I have a upload image script and now I want update uploaded images in my database. I have used a php foreach loop and radio input for show each image and select which image is updated now my problem it's: when I select a radio bottom only send a random value with jquery to my php file but I want send only my selected radio value to my php file. My php loop is:

<?php foreach($images as $image) { ?>

<?php $src = JURI::base().'images/discount/'.$image['name']; ?>
<input type="radio" name="imgname" id="imgname" value="<?php echo $image['name'] ?>"><img src="<?php echo $src ?>" alt="" height="100" width="100" />

 <?php } ?> 

And this part of my jquery send radio value to my php file:

vpb_data.append('imgpath', $('#imgpath').val());
saber
  • 336
  • 5
  • 15
  • 1
    Try out this links---> 1.http://stackoverflow.com/questions/986120/how-to-get-the-value-of-a-selected-radio-button-using-its-name-in-jquery 2.http://stackoverflow.com/questions/596351/how-can-i-get-which-radio-is-selected-via-jquery – narasimharaosp Apr 11 '14 at 12:25

2 Answers2

2

Try this -

$(function(){
   $("#imgpath").on('click',function(){
       var value = $(this).val();
       vpb_data.append('imgpath', value);
   });
});
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47
0

I found how can do it I change my jquery to this and it's work:

vpb_data.append('imgname', $('input:radio[name=imgname]:checked').val());
saber
  • 336
  • 5
  • 15