Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Yesterday I have put the question which was answered correctly but now I want to convert that same code into javascript. I have made some changes but its not work

working code- http://jsfiddle.net/SXzyR/8/

mycode- http://jsfiddle.net/SXzyR/11/

share|improve this question

closed as off topic by Rory McCrossan, hjpotter92, Jamiec, M42, wich Oct 18 '12 at 10:15

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
This type of question, where you're looking to refactor working code, should be posted on codereview.stackexchange.com –  Rory McCrossan Oct 18 '12 at 7:57
    
jQuery is JavaScript... but I take it you're trying to ditch jQuery –  Elias Van Ootegem Oct 18 '12 at 7:58

2 Answers 2

up vote 1 down vote accepted

You want to use this.id instead of document.getElementById(this) to get the id string where this is a DOM element.

share|improve this answer
    
why document.getElementById(this) not working –  amit Oct 18 '12 at 8:01
1  
@amit, because this references the element, not the id of the element –  Elias Van Ootegem Oct 18 '12 at 8:07

Please read some tutorials about jQuery. This is a good start, also have a look here.

jQuery isn't another language, it's a library for JavaScript. Considering the following line from your "translated" code:

txtval(document.getElementById(this)

Instead of writing document.getElementById you can simply use jQuery to write

txtval($(this))

as in the first example (working code).

Also you are mixing jQuery with "native" JavaScript/DOM functions in your code. Don't reinvent the wheel, use jQuery to accomplish your task.

share|improve this answer
    
tried but not working txtval(document.getElementById(this) –  amit Oct 18 '12 at 8:00
    
@amit try document.getElementById(this.id) or document.getElementById($(this).attr('id')) to pass the id, not the DOM element... –  Elias Van Ootegem Oct 18 '12 at 8:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.