Search code examples
javascriptphpimageupdatingautofill

Img scr not updating


so basically what i'm trying to do is to updating the images scr without refreshing the website. Well, it works if i refresh the website but the user can't see that image he choose. So user need to refresh the page first.

The img tag <img class="tInput" id="ImageType" src="<?php echo $this->item->houses_ImageType; ?>" alt="0" />

It's a autofill form, the texts works. <input class="tInput" type="text" name="house_video" id="video" size="50" maxlength="250" value="<?php echo $this->houses->video; ?>" />

<input name="house_title" value="<?php echo $this->houses->house_title; ?>" class="tInput" id="game_title" tabindex="1"/>

The javascript code

                $itemrow.find('#house_title').val(ui.item.itemTitle);
                $itemrow.find('#House_Type').val(ui.item.HouseType);
                $itemrow.find('#ImageType').val(ui.item.ImageType);
                $itemrow.find('#house_video').val(ui.item.itemVideo);

In my joomla site i created a small component (with some help), there i create a field with the houses title, image, video,etc... It's connecting to my database, the database field for the image is just a textbox. There i put the image path (/images/items/house145.jpg) and that's it.

If users want to search something like house with 3 bedrooms, then all the information is filled automatically, also the image field, but you need to refresh the page then the image is showing up. If users search for 5 bedrooms then he need again to refresh the page, because the image from 3 bedrooms is still showing up.

Did i something missed?


Solution

  • You can't change image's source with val function. You can do it by changing src attribute's value.

     $(elem).attr('src', newSource);
    

    So in your case :

     $itemrow.find('#House_Type').attr('src', ui.item.HouseType);
    
     $itemrow.find('#ImageType').attr('src', ui.item.ImageType);