...

View Full Version : Help with Combo Box Image Selector



kjreif
08-07-2008, 09:43 PM
I'm new to JavaScript and I'm trying to alter this script (that I got from here) a little bit, and I'm wondering if anyone could help me out. The script works great by taking the value from the option tag and changing the image. My problem is that, I need the value to be not the entire image path, but rather just a letter because the form also links up to my sql database where I need the data from that inserted. So for example instead of having the value="images/a.jpg" I would need it to be value="a" so that "a" gets inserted into the database instead of the whole path. Is there a way to alter the return value so it has the path then the value then the extension? For example path/VALUE/.jpg (where path and value are always the same).

I hope this makes sense - and thanks in advance for your help!

Kelly


function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
}

Arty Effem
08-08-2008, 02:43 PM
My problem is that, I need the value to be not the entire image path, but rather just a letter because the form also links up to my sql database where I need the data from that inserted. So for example instead of having the value="images/a.jpg" I would need it to be value="a" so that "a" gets inserted into the database instead of the whole path.
I think this does what you need:
function showimage()
{
if (document.images)
document.images.pictures.src=document.mygallery.picture.value.replace(/images\/([^\.]+).+$/, "$1");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum