Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to change the display between two image buttons based on the javascript validation?

Posted on 2008-10-17
6
Medium Priority
?
247 Views
Last Modified: 2012-05-05
I have two image buttons. One is shown as enabled and the other one is shown as disabled. But only one will be shown at a time.
I need to show these buttons based on a javascript validation. By default disable button will be shown.
The validation is that on entering 5 characters into a textbox the button will be changed to enable button.
It is basically switching between image buttons based on a javascript validation.

Any help is greatly appreciated!
Thank you
0
Comment
Question by:ipjyo
  • 3
  • 2
6 Comments
 
LVL 9

Assisted Solution

by:vavjeeva
vavjeeva earned 400 total points
ID: 22746954
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22747937
>> By default disable button will be shown.
How do you hide the "enabled" button by default? Visible=False?
0
 

Author Comment

by:ipjyo
ID: 22748079
yes, I am using Visible=False property for the enable button. I need to show this button in place of the default disable button on javascript validation. Can we use place holder in this case so I can show these buttons at the same place on the screen?

thanks!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Accepted Solution

by:
prairiedog earned 1600 total points
ID: 22748979
Well, if you set Visible=False, then the button will not be rendered on the page at all, and JavaScript will not be able to find it. So you can't use JavaScript to find it because it is not there. Run you application to load the page, then view Page Source of the page, you will find that there is only one button generated: the "disable" button.

What you can do is: instead of setting Visible=False for the enable button, you add a style on the image button: <div id="divEnable style="display:none"><asp:ImageButton ID="enableButton" runat="server" ></imageButton></div>
For disable button, you can do the similar thing: <div id="divDisable" style="display:block"><ImageButton ID="disableButton" runat="server"></ImageButton></div>

The JavaScript function will be:
<script language="JavaScript" type="text/javascript">
     function enableDisableButton()
     {
          var txt = document.getElementById('<%=TextBox1.ClientID%>');
          if (txt.value.length >=5)
          {
               document.getElementById('divEnable').style.display="block";
               document.getElementById('divDisable').style.display = "none";
          }
          else
          {
              document.getElementById('divEnable').style.display="none";
              document.getElementById('divDisable').style.display="block";
          }
     }

</script>

The TextBox will something like this:
<asp:TextBox ID="TextBox1" runat="server" onkeyup="enableDisableButton"></TextBox>
0
 

Author Comment

by:ipjyo
ID: 22749422
thanks for the solution..I will try this and let you know
0
 

Author Comment

by:ipjyo
ID: 22768768
Thank you..It worked for me..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question