Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  94] [ 2]  / answers: 1 / hits: 40173  / 10 Years ago, mon, july 21, 2014, 12:00:00

I would like to add an onchange event to those input fields without jquery:



<input type=text id=cbid.wizard.1._latitude>
<input type=text id=cbid.wizard.1._longitude>


I can already call the object with



<script type=text/javascript>
alert(document.getElementById('cbid.wizard.1._latitude').id);
</script>


In the end, I want to add this behaviour, that if you enter a pair of coordinates into the first input, I will spread the pair over the two input fields?



How do I add an onchange event with javascript?


More From » javascript

 Answers
7

Ummm, attach an event handler for the 'change' event?



pure JS



document.getElementById('element_id').onchange = function() {
// your logic
};

// or

document.getElementById('element_id').addEventListener(
'change',
callbackFunction,
false
);


jQuery



$('#element_id').change(function() {
// your logic
});


Note



Note, that change event on the text field will be fired after the blur event. It's possible that your looking for keypress event's or something like that.


[#70119] Friday, July 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamila

Total Points: 490
Total Questions: 94
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;