Help with writing JavaScript code in notepad?
-
How do i create an html document with a function in the head section named printPersonalInfo(), and within this function use the document.write() and document.writeIn() methods to print my name,adress,date of birth, and social security number on the screen. I need to call the function from the body section of the document. Can someone please help! CODE SO FAR BUT DOSEN"T WORK! <html><head> <title>Print Personal Info Function</title> <script language="JavaScript"> <!-- HIDE FROM INCOMPATIBLE BROWSERS function print_personal_info(personal_info) { document.writeIn(personal_info); } // STOP HIDING FROM INCOMPATIBLE BROWSERS --> </script></head><body> <script language="JavaScript"> <!-- HIDE FROM INCOMPATIBLE BROWSERS print_personal_info("John Doe", "Alpine Town","7/5/1986","000-00-000"); // STOP HIDING FROM INCOMPATIBLE BROWSERS --> </script></head></body></html>
-
Answer:
First, that's the document.writeln() method (with a lower-case L in the name where you have a capital I). I found that by copying your code, saving it as an HTML file, and running it. If you fix that, you'll find that it will write the "John Doe" and that's all. The reason is that you have four separate parameters in the call to your function, and only one argument defined. That argument, personal_info, is matched to the first parameter in the call, and that's all that's written. Change the function to function print_personal_info(name, hometown, birthdate, ssn) { document.writeln(name, hometown, birthdate, ssn); } and it works. (Of course, the fields are all run together, because no spacing was specified.) Now change the .writeln() call to document.writeln(name, '<br>', hometown, '<br>', birthdate, '<br>', ssn); and each field will appear on a separate line.
Sticky NY at Yahoo! Answers Visit the source
Other answers
in the head section, you wrote writeIn (with a capital i), instead of writeln (with a lowercase L). Also, remove the </head> from the last line.
AniDev
Related Q & A:
- How to encrypt JavaScript code?Best solution by Stack Overflow
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
- Help on writing a resume objective?Best solution by Yahoo! Answers
- Can you help to writing a cover letter?Best solution by eHow old
- Need help debugging a javascript?Best solution by allwebdevhelp.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.