Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-17
6
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

660 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