troubleshooting Question

How can I get this toggle to work?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
jQuery
2 Comments1 Solution14 ViewsLast Modified:
Here's my HTML:

<tr>
               <td>
               Vendor
               </td>
               <td>
               <select name="vendor" style="width:600px;" id="vendor">
                  <option></option>
                  <option name="third_party">Third Party</option>
                  <option name="cart">Cart</option>
               </select>
               </td>
            </tr>
            <tr style="display:none;" id="url_row">
               <td>
               URL
               </td>
               <td style="width:550px;">
               <input type="text" style="width:590px;" name="third_party_url" placeholder="Third Party URL">
               </td>
            </tr>
Here's my JQuery:

<script>

$(document).ready(function() {
   $("#vendor").change(function(e) {
      var value = $("#vendor option:selected").val();
      if(value=="Cart") {
         e.preventDefault();
         $("#url_row").css("visibility", "visible");
      }
      else {
         $("#url_row").css("visibility", "hidden");
      }
   });
});

</script>
What I want to do is create the JQuery that will reveal the "url_row" when the user chooses, "Third Party." And if they don't, "url_row" is either hidden on the select change or it merely remains hidden.

I used "toggle" initially, but the "url_row" simply alternated between being visible or hidden irrespective of what the value is.

So...

User chooses, "third_party" then "url_row" is displayed. Otherwise, it's hidden.

How do I pull that off?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros