Jump to content

javascript table & celect problem


Recommended Posts

<!DOCTYPE html>

  Select your favorite fruit:

Please tell us where the mistake is.
the result is "  orange" instead of "orange", I get a blank space in front of the data.





            <button type="button" onclick="myFunction(this)">Try it</button>
  <select id="mySelect">
    <option value="apple">Apple</option>
    <option value="orange">Orange</option>
    <option value="pineapple">Pineapple</option>
    <option value="banana">Banana</option>

function myFunction(td) {
 selectedRow = td.parentElement.parentElement;
    document.getElementById("mySelect").value= selectedRow.cells[1].innerHTML; 


Where I'm wrong.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...