[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

Click a textbox and navigate to a page

What is the javascript code or other approaches if server side code won't do
to navigate to a page when a textbox is clicked since Textbox does not have a click event?
0
zachvaldez
Asked:
zachvaldez
  • 6
  • 5
1 Solution
 
Amar BardoliwalaCommented:
Hello zachvaldez,

why would you want to navigate on textbox click? It is not something that is used generally.

I am not much aware of .NET textboxes but in html text boxes click event is there.

Look at following link

http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_events.aspx


Hope this will help you.

Thank you

Amar Bardoliwala
0
 
leakim971PluritechnicianCommented:
add this in the head section of the page :
<script type="text/javascript">

window.onload = function() {
   document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
            location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";
   }
}

</script>

Open in new window


where TextBox1 is the ID of your textbox

http://beyondrelational.com/modules/2/blogs/61/posts/11206/all-about-client-id-mode-in-aspnet-4.aspx
0
 
zachvaldezAuthor Commented:
there is a syntax error looking for a missing ";" somewhere..
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
leakim971PluritechnicianCommented:
not in my code... generally not in javascript
0
 
zachvaldezAuthor Commented:
ok I found the error and it worked .However, If I set the textbox to readonly, this thing would would not work.
I don't want the ability to edit the textbox but can only be clicked and navigate to the url.
Is it possible to set textbox  not editable  with keyup event?
0
 
leakim971PluritechnicianCommented:
>If I set the textbox to readonly, this thing would would not work.

That's wrong until you're using .net to do that....

use readonly="readonly"

<asp:TextBox id="TextBox1" runat="Server" ></asp:TextBox>

Open in new window


<script type="text/javascript">

window.onload = function() {
   document.getElementById("<%= TextBox1.ClientID %>").setAttribute("readonly", "readonly");
   document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
            location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";
   }
}

</script>

Open in new window

0
 
zachvaldezAuthor Commented:
Is it possible to add another textbox "textbox2" for instance and navigate it to a diff. url?
I tried to do that but did not work.
Should I repeat the window.onload for it to work?
0
 
leakim971PluritechnicianCommented:
>Is it possible to add another textbox "textbox2" for instance and navigate it to a diff. url?

yes

>I tried to do that but did not work.

so post a link to you page or you code...
0
 
zachvaldezAuthor Commented:
well I just add the code..

window.onload = function() {
   document.getElementById("<%= TextBox1.ClientID %>").setAttribute("readonly", "readonly");
   document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
            location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";

 document.getElementById("<%= TextBox2.ClientID %>").onclick = function() {
            location.href = "school.aspx";

   }
}
0
 
leakim971PluritechnicianCommented:
You just miss a bracket
window.onload = function() {


   document.getElementById("<%= TextBox1.ClientID %>").setAttribute("readonly", "readonly");



   document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
            location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";
    }




 document.getElementById("<%= TextBox2.ClientID %>").onclick = function() {
            location.href = "school.aspx";
   }




}

Open in new window

0
 
zachvaldezAuthor Commented:
I forgot to mention I also have a query string added at the end of

location.href = "school.aspx?hid=xxxxx"; for example

How will I add the querystring value?
0
 
leakim971PluritechnicianCommented:
create a new question...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now