• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

ASP.NET

How do i capture when a user clicks out of a text box for some reason the only time textchange fires up is when I hit the enter key?? Any idea!!
0
DRSLT
Asked:
DRSLT
  • 5
2 Solutions
 
UnexplainedWaysCommented:
<html>
<head>
<script language=javascript>

      function DoThat()
      {
            alert("stuff");
      }

</script>
</head>
<body>

      <input type=text onchange=DoThat()>

</body>
</html>


0
 
UnexplainedWaysCommented:
Problem is it only works when you click in it, and then modify it, however the event is only called when you leave the box and not after every click.

Also, i know you asked for asp.net, however all you need to add is the javascript.  Server side code wont work for this.  
0
 
UnexplainedWaysCommented:
And back to the point of the question:

"the only time textchange fires up is when I hit the enter key??",

I'm thinking because asp.net is server side code.  The only time it can do something is when the user posts back.  So the only time it can check to see if the text is changed is when the submit button is clicked.  If you want something to happen client side you need javascript, and the first post will solve that.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
UnexplainedWaysCommented:
Just played with it a bit more, and if you use 'onBlur' instead of 'onchange' in the example i showed, it should do the trick.

(If there was an edit button i would use it, dam these multiple posts)
0
 
DRSLTAuthor Commented:
How do you call an already exsiting function from the java script? I have a function call ..._TextChanged and it is in the aspx page i want to have the java script call it whenever it gets inside the above function?


Thanks,
0
 
UnexplainedWaysCommented:
"I have a function call ..._TextChanged and it is in the aspx page"

If you have something in the aspx page, then you will require the whole page to be submitted.





<html>
<head>
<script language=javascript>

      function AlertSoUKnow()
      {
            alert("Page has been reloaded");
      }


      function DoThat()
      {
            element = document.getElementById("theForm");
            theForm.submit();

      }

</script>
</head>
<body onload=AlertSoUKnow()>
<form id=theForm>

      <input type=text value=DoThat onBlur=DoThat()>
</form>

</body>
</html>




And then in your aspx_page, my guess is that you would need to say

if(textbox changed)
{
  call ..._TextChanged
}




How to do "textbox changed" i'm not quite sure because i haven't done it, but here's a few ideas:

1) Have a hidden field, that is set to true or false.  The defaul is false, during the DoThat() function, change it to true, so when the page is submitted, you check the hidden field to see if it has changed.

2) Have the previous value stored and then compare the 2, different then call the function.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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