turpentyne Posted August 17, 2010 Share Posted August 17, 2010 Ok. I'm stumped. I have a dropdown from a form that passes a couple variables to a function that changes an image. It works just fine. But I quickly realized that if a user clicks again on the dropdown to change their option, the image link breaks because the url wasn't the same as I'd set up the code for. So I'm trying to put in a couple "else if" conditions to account for those, but it's not working. The url is still wrong. It's adding a folder to the filepath, but not deleting the one it should replace. Hope that made sense. Here's the code: function change3(picName,choice) { var url = (document[picName].src); if (/leaf_shapes\D{1}/.test(url)) { url = url.replace(/leaf_shapes/,"leaf_shapes/" + choice) document[picName].src=(url); } else if (/leaf_shapes\D{1}crenate/.test(url)) { url = url.replace(/leaf_shapes/crenate/,"/leaf_shapes/" + choice) document[picName].src=(url); } In case it helps, here's the dropdown that the information comes from: <div id="megamenu4" class="megamenu"> <div class="column"> <ul> <li id="margin1"><a href="javascript:passit4('entire')" onclick="ShowContent('uniquename3'); change3('pic2','entire');" >Entire</a></li> <li id="margin2"><a href="javascript:passit4('undulate')" onclick="ShowContent('uniquename3'); change3('pic2','margin_undulate;')" >Undulate</a></li> <li id="margin3"><a href="javascript:passit4('crenate')" onclick="ShowContent('uniquename3'); change3('pic2','crenate');" >Crenate</a></li> <li id="margin4"><a href="javascript:passit4('finely dentate')" onclick="ShowContent('uniquename3'); change3('pic2','margin_finelyserrate');" >Finely Serrate</a></li> <li id="margin5"><a href="javascript:passit4('serrate')" onclick="ShowContent('uniquename3'); change3('pic2','serrate');">Serrate</a></li> </ul> </div> </div> Quote Link to comment Share on other sites More sharing options...
turpentyne Posted August 17, 2010 Author Share Posted August 17, 2010 I forgot to add in the url in its original form, just in case it helps avoid any confusion. It is: <IMG SRC="images/leaf_shapes/1of30images.gif" name="pic2"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.