简体   繁体   中英

JavaScript simple echo/print query

I know this is basic stuff, but after hours of research on google, this site and others I simply cannot come up with an explanation of why this code wouldnt work. And it doesnt. Can someone please spot the mistake? many thanks in advance:

The JavaScript bit:

<script language="text/JavaScript">

function myFunction() {

var date1;
date1=getElementByID("date1").value;

document.getElementByID("calculate").innerHTML=date1;

}

</script>

The HTML bit (that definitely works and its a rather large file with loads of forms, tables)

       <html>
<head></head>
<body>
    <div id="wrap">
<h2>JavaScript</h2>
<form>
<table>
<tr>    
<th><input type=text id="date1" value="09:00" size=15></td></th></tr></table></form>

<table>
<tr>    
    <th bgcolor="#eeaaaa" align=center><em></em> <input type=button id=pay id="calculate" size=15 value="Click"></th></tr></table>

<table>
<tr>    
    <th><p id="calculate" size=15> </p></td></th></tr></table>
    </div>
</body>
</html>

I tried different things already, changing the syntax, clearing the clutter out, but nothing seems to work.

I appreciate any constructive comments/criticism. Thanks

You have two ids id=pay id="calculate" for your second input .. id needs to be unique

<script language="text/javascript">

function myFunction() {

var date1;
date1=document.getElementById("date1").value;

document.getElementById("calculate").innerHTML=date1;

}

</script>

and most importantly ..you are not calling myFunction

#calculate (the element with id="calculate" ) is an input element. You don't set its value using innerHTML but value (like you did when reading the value in #date1 .)

You may want to use an online HTML validator or at least a more powerful HTML editor to help you out with the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM