AnswerBun.com

How can I pass date/text to ?

Stack Overflow Asked by Muska on December 15, 2020

I’m trying to set text in input date but nothing shows there.
Is it something wrong with data type?

<!DOCTYPE html>
<html>
<body>

<table>
    <tr>
        <td id="invoice">
        2020-09-22
        </td>
    </tr>
</table>    

<select id="decisionList">
  <option></option>
  <option>Payment date</option>
</select>

<div id="choice">
</div>



<script>

document.addEventListener("change", function () {

  var decisionList = document.getElementById("decisionList");
  var selectedOptionIndex = decisionList.options[decisionList.selectedIndex].index;  
  
  var invoiceDate = document.getElementById("invoice");
  var invoiceDateText = invoiceDate.textContent;
  
  var finalChoice = document.getElementById("choice");

  switch(selectedOptionIndex) {
    
    case 0:
        finalChoice.innerHTML='<input type="date">'
    break;
   
    case 1:
        finalChoice.innerHTML='<input type="date" value="' + invoiceDateText + '">' //here is a problem
    break;

    default:
    
    finalChoice.innerHTML=''
    
  }
  
})

</script>

</body>
</html>

I also tried to create new Date based on text I’m passing:

  var newDate = new Date(invoiceDateText);

but also doesn’t work. As you can see I’m passing 2020-09-22 (from td) so where is the problem?

2 Answers

The variable invoiceDateText contains white spaces and therefore is not parsed correctly.

You can update that part to the following.

 var invoiceDateText = invoiceDate.textContent.trim();

Correct answer by Ali Ihsan on December 15, 2020

The date should be a string and formatted by YYYY-MM-DD

Answered by triston_h on December 15, 2020

Add your own answers!

Related Questions

How Can I Not Double Count Rows And Objects In My Query?

3  Asked on November 22, 2021 by ziegler199

       

Login with active directory

0  Asked on November 20, 2021 by artisan

       

External CSS not linking for all elements

1  Asked on November 20, 2021 by stratos-la

   

Why is ‘u{1D11E}’.charAt(0) not equal to ‘u{1D11E}’?

2  Asked on November 20, 2021 by json-prime

     

E: Unable to locate package python3-boto3

2  Asked on November 20, 2021 by rosi-darmawati

       

x and o in tic tac toe keeps alternating

0  Asked on November 20, 2021 by channee-mathmath

     

Remove using a button

2  Asked on November 20, 2021 by gastn

   

remove 0 and add ‘ ‘ in every number in pandas

1  Asked on November 20, 2021 by spt-hsb

   

nav-tabs doesn’t change on click

0  Asked on November 20, 2021 by beureu

     

Stick element on bottom on page scroll

3  Asked on November 20, 2021

         

Exchange each 100 in a dataframe for another value

1  Asked on November 20, 2021 by tarik-benrabah

     

GraphQL & Using a nested subscribe function

1  Asked on November 20, 2021 by u-rogel

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP