Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input id= "test1" value="test1" onchange="test(this.id)">
- <input id= "test2" value="test2" onchange="test(this.id)">
- <input id= "test3" value="test3" onchange="test(this.id)">
- <!-- https://stackoverflow.com/questions/8976627/how-to-add-two-strings-as-if-they-were-numbers -->
- <!-- parseInt and numbers addition possible fix below -->
- <!-- +id + +1 -->
- <script>
- function test(string) {
- var id = string.replace("test", "");
- alert('curid' + parseInt(id));
- alert('previd' + parseInt(id-1));
- alert('nextid' + parseInt(+id + +1));
- var curElement = document.getElementById("test" + parseInt(id));
- var prevElement = document.getElementById("test" + parseInt(id-1));
- var nextElement = document.getElementById("test" + parseInt(+id + +1));
- if (curElement) {
- alert('current element: ' + curElement.value);
- }
- if (prevElement) {
- alert('previous element: ' + prevElement.value);
- }
- if (nextElement) {
- alert('next element: ' + nextElement.value);
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement