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
https://forums.phpfreaks.com/topic/210929-url-change-on-else-if-doesnt-work/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.