Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Combo Box Image Selector

    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
    }

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by kjreif View Post
    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:
    Code:
    function showimage()
    {
     if (document.images)
       document.images.pictures.src=document.mygallery.picture.value.replace(/images\/([^\.]+).+$/, "$1");
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •