1

I'm embarassed to ask but I need help getting these scripts to work together and output what I'm looking for:

HEAD section, first script:

function copyToClipboard(s) {
if (window.clipboardData && clipboardData.setData) {
    clipboardData.setData('text', s);
}
}

HEAD section, second script:

var name=prompt("Enter your first and last name please.","name");

function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}

BODY section:

 <button type="button" onclick="displayDate()">Display Date</button>
 <strong><a href="javascript: void(0)" id="copy" onclick="copyToClipboard(document.getElementById('time').innerHTML)"><span id="time">Date and time will display here</span></a></strong>

So basically what I'm trying to accomplish here is a webpage that prompts the user to enter their first and last name when the page loads. Then when they click the button that's labeled "Display Date", the span labeled "time" should change to something like:

Edited on Thu Jan 01 12:59:59 2099 by John Doe

The way I have the current script is giving me a "Unterminated string constant" error when the page loads. When I click the button I get an "Object expected" error.

Can anyone provide any suggestions please?

2 Answers 2

1
function displayDate()
{
   document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}

You do have an unterminated string. Check after the name variable.

Sign up to request clarification or add additional context in comments.

Comments

0
var name=prompt("Enter your first and last name please.","name");

function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.