简体   繁体   中英

Cant figure out why a name is not showing up in the div

When ever I click enter your name nothing pops up in the div tag. My goal is to try to make the name appear in all the span tags with different id's. But it wont even appear in one. I am also using pure JavaScript

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="DreStone.css">
 <title> o </title>
<style> 

</style>

       <!-- JAVASCRIPT -->
    <script src="util.js"></script>

<script> 
/**********************
LOCAL NAMESPACE OBJECT
***********************/
var z={};


/**********************
EVENT HANDLERS
***********************/
z.showName = function()
  { var age = u.eid("names").value,
  u.eid("firstname").innerHTML = "" + age;

}  

/**********************
WINDOW.ONLOAD
***********************/
window.onload = function()
{ 
u.eid("nameinput").addEventListener('click', z.showName);
} 

</script> 

</head> 

<body> 

Please enter your name: <input id="names" type="text"> 

<button id="nameinput" type="button">Click after you enter your name</button>

<p> 
How is your day going <span id="firstnam"> </span>
  </p> 
<div>        I would like to you to take a look at this payment plan <span id="secondname"> </span>.
It may prove to be very valueable to you. If you do not care then ignore this.  Thank you <span id="thirdname"> </span> 
</div>
<div id="firstname">
</div> 
</body>
</html> 

Any help at all would be really useful. Thanks

How about changing it to a replace function? Something like:

document.body.innerHTML = document.body.innerHTML.replace("How is your day going", "How is your day going " + document.form[0].user.value] + "?");

Assuming u.eid() is within util.js and works, you have (,) instaed of (;)

/**********************
EVENT HANDLERS
***********************/
z.showName = function()
  { var age = u.eid("names").value;
  u.eid("firstname").innerHTML = "" + age;

} 

Try this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
 <title> o </title>
<style> 

</style>

<script> 
/**********************
LOCAL NAMESPACE OBJECT
***********************/
var z={};


/**********************
EVENT HANDLERS
***********************/
z.showName = function()
  { var age = document.getElementById("names").value;
  document.getElementById("firstname").innerHTML = "" + age;

}  

/**********************
WINDOW.ONLOAD
***********************/
window.onload = function()
{ 
document.getElementById("nameinput").addEventListener('click', z.showName);
} 


</script> 

</head> 

<body> 

Please enter your name: <input id="names" type="text"> 

<button id="nameinput" type="button">Click after you enter your name</button>

<p> 
How is your day going <span id="firstnam"> </span>
  </p> 
<div>        I would like to you to take a look at this payment plan <span id="secondname"> </span>.
It may prove to be very valueable to you. If you do not care then ignore this.  Thank you <span id="thirdname"> </span> 
</div>
<div id="firstname">
</div> 
</body>
</html> 

This is working for me

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