I was using map function in my code but it simply do not work! I must be doing some silly mistake but I am not able to find it out.
Can you Gurus help?
Here is the code:
<!DOCTYPE html>
<html>
<head>
<script>
getID = (x) => x.id;
getText = (x) => x.value;
function Click(x) {
input = document.getElementsByTagName("input");
alert(Array.from(input.map((x.id == "id") ? getID : getText)));
}
</script>
</head>
<body>
<input type="input" id="input1"> </input>
<input type="input" id="input2"> </input>
<button id="id" onclick="Click(this)"> ID </button>
<button id="text" onclick="Click(this)"> Text </button>
</body>
</html>
What I want it done is like this: When I click button "ID", list of IDs of the input field should be displayed. Likewise, when I click button "Text", it should display the list of texts which the input fields have currently. The functions getID and getText extracts the ID or text respectively when the argument is a single input field.
Regards,
Pravin Kumar.