JavaScript setAttribute is not working in JavaScript setattribute not working javascript

I am using setAttribue as below. Its working only for first time and after that the changing value is showing the alert but not setting with document.getElementById("to").setAttribute("value", selValue);

document.getElementById("listcontact").onchange = function () {
    var selIndex = document.getElementById("listcontact").selectedIndex;
    var selValue = document.getElementById("listcontact").options[selIndex].innerHTML;
    var contactVal = selValue.split(';');      
    var phone = contactVal[2];  

    alert(phone);
    document.getElementById("to").setAttribute("value", selValue);
    selIndex = "";
    selValue = "";
    phone = "";
    selValue = "";
};

Why is this not working as I expect and how can I fix it?

Answer:1

The value attribute sets the initial value, not the current value.

Assign something to the value property instead.

document.getElementById("to").value = selValue;
Answer:2

I would like to have an automated email sent to a person's email when they press a button. I'm having a few problems, one I am not sure what the JavaScript for this would be. Two, I don't know how to ...

I would like to have an automated email sent to a person's email when they press a button. I'm having a few problems, one I am not sure what the JavaScript for this would be. Two, I don't know how to ...

  1. sending automated emails
  2. sending automated emails outlook
  3. sending automated emails gmail
  4. sending automated emails from salesforce
  5. sending automated emails from google sheets
  6. sending automated emails from excel
  7. sending automated emails from jira
  8. sending automated emails from sql server
  9. sending automated emails using python
  10. sending automated emails from python
  11. sending automated emails using c# windows service
  12. sending automated emails from access
  13. sending automated emails from sharepoint
  14. sending automated emails using java
  15. sending automated emails from access 2010
  16. sending automated emails using c#
  17. sending automated emails from outlook 2010
  18. sending automated emails php
  19. sending out automated emails outlook
  20. sending automatic reminder emails outlook

I know I could use variations of this answer to find out how many different types of data there are in an array: How to count the number of certain element in an array? But, what I am looking for ...

I know I could use variations of this answer to find out how many different types of data there are in an array: How to count the number of certain element in an array? But, what I am looking for ...

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

  1. websocket with handshake
  2. websocket handshake in c
  3. websocket handshake for ssl
  4. websocket bad handshake with resp

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...