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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...