Jump to content

url change on else if doesn't work


turpentyne

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.