Write a HTML code to display your name.
Write a HTML code to display your name.
<HTML>
<HEAD>
</HEAD>
<TITLE> Your Name </TITLE>
<BODY>
Your Name
</BODY>
</HTML>
Write a HTML code to display your name.
<HTML>
<HEAD>
</HEAD>
<TITLE> Your Name </TITLE>
<BODY>
Your Name
</BODY>
</HTML>
Hi Ishara,
The easiest way to do is using JavaScript. Let’s divide this into two steps.
1. When the page loads you have to ask the name.
2. When user types the name it must display on the screen.
Let’s do the first step
<html>
<head>
<script>
</script>
</head>
<body>
</body>
</html>
Point : Must ask when the page loads
To do that we need the event attribute ‘onload’ of body tag
Syntax
onload="JavaScriptCode" JavaScriptCode : Required. JavaScript to be executed when the event occurs |
So we write in the body tag
<body onload="askname()">
Askname() is the JavaScript function that will be executed when the page loads
Let’s write that function inside the script tags.
<script>
function askname(){
}
</script>
Now we are going to ask the name. To do this we use ‘prompt’, JavaScript inbuilt function.
A prompt box used when we want user to input a value before entering a page. When a prompt box pops up, it will displays a text box and ‘Ok’, ‘Cancel’ buttons. To proceed user have to click either Ok or Cancel. If user clicks Cancel it will return null and if user clicks Ok it will return the value of the text box.
Syntax
prompt("sometext","defaultvalue"); |
function askname(){
var name=prompt("Please enter your name","Harry");
}
In here we assigned the value that returns from the prompt box to variable name.
So now we completed the 1st step. Now move onto 2nd step.
var name=prompt("Please enter your name","Harry");
if (name!=null && name!="") {
}
If the condition success we need to display the name on the screen and title.To do this we write the code like this.
document.write("Hello " + name);
We append the String “Hello” before the name by using concatenated symbol ‘+ ‘ and then write it on the body tag.
document.title = name;
We assign the value of variable name to the title.
So now the work is done. This kind of programming is called document object Modeling (DOM) which means the content created dynamically. Hope you got the idea.
here are the simple code for showing NAME in html:
<HTML>
<Head>
<Title> My Home Page </Title>
</Head>
<Body>
<center><h1>Hello My Name is ABC</h1></center>
</Body>
</HTML>
This simple code shows name in the center of the page,
In TITLE tag shows the title of the browser and CENTER tag shows the Name on the center of the page and H1 tag format the text in heading1 format. and finally close the BODY tag and HTML tag.
have a nice coding
HTML is markup language which is used to design web pages. HTML is very simple language to learn. Everyone can learn it easily. To create web pages by using HTML tags you need a text editor to write HTML tags as an example windows notepad also you need a web browser to display the web page.
This is the simple or basic<! — HTML code structure to create a web page– >
<HTML> <!–Starting HTML tag this tag is used define this is HTML page– >
<HEAD><! — Starting head tag– >
:<!–This is header area of the web page– >
<TITLE><! — this is the Title of the web page</TITLE>
</HEAD><!–ending header tag– >
<BODY><!–starting body tag– >
<!–This is the area which is displayed in the web browser– >
</BODY><!–ending body tag– >
</HTML><!–ending html tag– >
To display your name on the web page we can us various types of methods or HTML codes
<HTML>
<HEAD>
<TITLE> Display my name</TITLE>
</HEAD>
<BODY>
My name is your name<! — this just displays a normal text– >
<br/>: break tag
<H1>my name is your name</H1><! — This displays bold and large size letters– >
<Font size="size between 1 to 7" color="you can use color name or color codes" face="using font if needed">my name is your name</Font>
<! — This displays text according to the attributes you used– >
</BODY>
</HTML>
There are also other ways of displaying your name using HTML coding but these methods are very easy to understand
To write an HTML code to display your name it is so simple what you have to do you have to start the HTML code from a header tag which is started as HTML and end with HTML you can write the code as below.
<html>
<body>
<title> Your Name <title/>
<p1> SAME <p1/>
<body/>
<html/>
write these code in you note pad and save with extension as html.Now open the file with any explorer. You will see your name is displayed on the screen.This is also used in Making the front end view of the web page. Hope this will solve your problem and thanks for asking in techyv.com. thanks