TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
JavaScript lastIndexOf() Method
Ankit Bansal
Mar 09
2015
Code
1.4
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"index2.aspx.cs"
Inherits=
"MyApp.index2"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
<script type=
"text/javascript"
>
function getTopLevelDomain() {
var url = document.getElementById(
"txtURL"
).value;
if
(url ==
""
) {
alert(
"Please enter a valid URL"
);
document.getElementById(
"txtURL"
).focus();
}
else
{
var domain = url.substring(url.lastIndexOf(
"."
));
document.getElementById(
"txtDomain"
).value = domain;
}
}
</script>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<table style=
"border: 1px solid blue; font-family: 'Comic Sans MS'"
>
<tr>
<td>
<h3>Top level Domain Checker</h3>
</td>
</tr>
<tr>
<td>Enter the URL :
</td>
<td>
<input id=
"txtURL"
type=
"text"
/>
</td>
<td>
<input id=
"btnFetch"
type=
"button"
value=
"Fetch"
onclick=
"getTopLevelDomain();"
style=
"font-family: 'Comic Sans MS'"
/></td>
</tr>
<tr>
<td>Top Level Domain : </td>
<td>
<input id=
"txtDomain"
type=
"text"
disabled=
"disabled"
/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
JavaScript