Click here to Skip to main content
15,921,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How come jQuery/Javascript did not execute what i want it to be? I am using a DropDownList whereby an image will be shown at the side according to the value users select in my DropDownList. However, when i run it, nothing happen. Is this due to my .cs code which causes the problem or my .apsx?

Here is my .cs code:

C#
protected void weddingPlanner_SelectedIndexChanged(object sender, EventArgs e)
   {
       if (weddingPlanner.SelectedIndex == 0)
       {
           Image1.Visible = false;
       }
       else if (weddingPlanner.Text == "Planner1")
       {
           Image1.Visible = true;
           Image1.ImageUrl = "~/Images/pw1.png";
       }
       else if (weddingPlanner.Text == "Planner2")
       {
           Image1.Visible = true;
           Image1.ImageUrl = "~/Images/pwt1.png";
       }
       else if (weddingPlanner.Text == "Planner3")
       {
           Image1.Visible = true;
           Image1.ImageUrl = "~/Images/pwt2.png";
       }
       else if (weddingPlanner.Text == "Planner4")
       {
           Image1.Visible = true;
           Image1.ImageUrl = "~/Images/pwt3.jpg";
       }
       else if (weddingPlanner.Text == "Planner5")
       {
           Image1.Visible = true;
           Image1.ImageUrl = "~/Images/pwt4.jpg";
       }
   }


Here is my .aspx code:

C#
<script src="jQuery-1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
   $(document).ready(function() {
      $('#Image1').hide();
      $('#weddingPlanner').click(function() {
       $('#Image1').show('slow');
       return false;
     });
      $('#weddingPlanner').click(function() {
       $('#Image1').hide('fast');
       return false;
     });
   </script>
Posted
Comments
Sibasisjena 17-Jul-12 10:22am    
Hi kelly, you can do this functionality by using Jquery or in .cs page. First decide in using what you want to do that. If you will do it in jquery .cs code is not required vice versa.

1 solution

First thing is to make sure that the URL's referenced are correct and Images are visible when no condition is set and everything is visible.

Second thing is to share the HTML code based on which your jQuery code is written to confirm that the logic written is correct.

Third, based on what you have already shared, you implement click event functionality for weddingplanner twice! Surely, not intended to. Something wrong there, correct your logic.
C#
// first time
      $('#weddingPlanner').click(function() {
        $('#Image1').show('slow');
        return false;
      });

       // second time 
       $('#weddingPlanner').click(function() {
        $('#Image1').hide('fast');
        return false;
      });


BTW, next time, do add on what exactly the code was written for. Posting something like 'it does not do what i want' will not help as we can not guess that out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900