kozica Posted November 17, 2020 Share Posted November 17, 2020 <!DOCTYPE html> <html> <body> <form> 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. <table> <tr> <td> 1 </td> <td> orange </td> </td> <td> <button type="button" onclick="myFunction(this)">Try it</button> </td> </tr> </table> <select id="mySelect"> <option value="apple">Apple</option> <option value="orange">Orange</option> <option value="pineapple">Pineapple</option> <option value="banana">Banana</option> </select> </form> <script> function myFunction(td) { selectedRow = td.parentElement.parentElement; document.getElementById("mySelect").value= selectedRow.cells[1].innerHTML; } </script> </body> </html> Where I'm wrong. thanks. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 18, 2020 Share Posted November 18, 2020 Remove line breaks so its <td>orange</td> Sometimes line breaks that you are using are read as whitespace. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now