Solved

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

Posted on 2008-10-17
6
233 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 100 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Accepted Solution

by:
prairiedog earned 400 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now