How to handle textchanged event of textboxes inside formview using javascript instead of postback to server

I have multiple textboxes inside a formview on a asp.net page. when the text changed on any of the textbox, I'd like to check the textbox id, and depending on the name of the textbox, i'll get its value, do some calculations and update the text of the target  label or text box with the calculated value. There are lots of them so I'd prefer to use javascript and do it on the client side instead of using postback and do it on the server side.

I'm new to using javascript, so the more detail, the better.

Thanks in advance for your help.
eecpamericaAsked:
Who is Participating?
 
BadotzConnect With a Mentor Commented:
You can set the values of DIV and SPAN elements using the innerHTML attribute:

document.getElementById('spanA').innerHTML = 'either plain text or <b><i>HTML</i></b>');
0
 
BadotzCommented:
Set up an "onchange" handler that accepts the self-reference from the textboxes:

<input id="tb1" onblur="boxtext_blur(this);" value="Textbox 1"></input>
<input id="tb2" onblur="boxtext_blur(this);" value="Textbox 2"></input>
etc.

function boxtext_blur(obj)
{
    id = obj.id // 'tb1' or 'tb2' or ...
    // do whatever you want here
}
0
 
eecpamericaAuthor Commented:
That great. I can reference the textbox passed into the function.

Now, how do I reference other label and textbox controls in the formview inside the function to set their values? I tried to lookup the id of those controls in the page source view and reference it  but it didn't seem to work.

Thanks much for your help.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
BadotzCommented:
If each HTML element has an ID - and all ID values *must* be unique - then you can reference each element like this:

var elemA = document.getElementById('tb1');

Now, elemA refers to the input element "tb1", and you can do what you want with it.

In this way, you can "reach out and touch someone", er, some HTML element ;-)

javascript is case-sensitive, so make sure you spell and cap things properly (getElementById, for example).
0
 
eecpamericaAuthor Commented:
Thanks a lot for your timely reply. It's very helpful.

One more question: the asp label was rendered as html span element,is it possible to set the text of it in the function, if yes,  how? I can set textbox value without problem.
0
 
eecpamericaAuthor Commented:
That did the trick. Thanks again.
0
 
BadotzCommented:
Since no one else participated in this question, what is the deal?

I have no idea what the point value of the question was before this comment, but if it was more the 250, why be stingy?

Signed,
Confused
0
 
eecpamericaAuthor Commented:
Your help was greatly appreciated.
0
 
BadotzCommented:
My confusion stems from this email message:

"The Asker has requested that this question be Closed, with some or all of the points awarded to participating Experts and one of the Asker's comments selected as the solution. If you object to this action, you have seven days to post a comment describing your objection. This will generate a request in Community Support for Moderator review. If no Expert objects, this question will be closed as described above."

Since no one else participated in this question, what is the deal?

I have no idea what the point value of the question was before this comment, but if it was more the 250, why be stingy?

Signed,
Confused
0
 
eecpamericaAuthor Commented:
Is there a way to check what point was chosen when I opened the question? or is there a way to add more point to it?  I thought it's 250. I'd like to give you all the points give since you've been very helpful and very timely as well. This is the first time I assign points.
0
 
BadotzCommented:
No worries - I had not seen that message before, and that is the reason for my confusion.

Glad to help ;-)
0
 
eecpamericaAuthor Commented:
Please give all the points to the expert Badotz who answered the question. He or she deserves it. I may have made mistake when assigning the point. If that's the case. please correct. Thanks.
0
 
BadotzCommented:
It's OK - save 'em for next time! I have more than enough poinks!
0
All Courses

From novice to tech pro — start learning today.