Duminda Chamara

Sunday, February 21, 2010

How to create javascript alerts


How to Create a JavaScript Alerts?




Following example shows you how to create a JavaScript Alerts.





JavaScript alert is a kind of message box that use to display some information to the user to gain his attention or prompt a input from the user. Suppose that you want to display an error message to the user. Using javascript alert you can do it easily. When you validate user inputs before submit to the server, you can use javascript alert to ask user to enter valid data. Also you can use a confirm dialog box to ask user to make sure that he entered correct data.


Demo- Create JavaScript Alerts.

JavaScript Alert Boxes
  JavaScript alert box show a message to the user.

You can display the message with multiple lines using '\n'
» How to create Simple JavaScript Alert Box
» How to break lines in a javascript alert message
» Display custom message in javascript alert
  Enter your Message
» Display screen size using an alert
» Display the URL of current web page
 
JavaScript Prompt Messages
  JavaScript prompt dialog box provide a text box to the user to enter

text input. Also you can define a default value. It returns user's input if

the user has entered a value. Otherwise it returns the default value.

But it returns 'null' if there is no any value present in the text box.
» Prompt user name
» Adding two numbers using prompt messages
 
JavaScript Confirm Messages
  JavaScript confirm dialog box returns true or false according to
user response. If user clicks on 'Yes' button it returns 'true'
and if user
clicks on 'Cancel' button or close the message window it returns 'false'
» Simple confirm message
» Use confirm dialog to go to another web page



Try It!

Bookmark and Share





1. Example code for create a alert box in javascript.

JavaScript Code

<script type="text/javascript" language="javascript">

<!--

function simpleAlert(){

window.alert("This is a simple javascript alert");

return false;

}

-->

</script>

HTML Code


<html>
<head><title>How to create a simple alert </title>
</head><body>
<table border="0"><tr>
<td>&nbsp;<input name="btnmessage" type="submit" id="btnmessage" onclick="javascript:simpleAlert();" value="Click Here " /></td>
<td>&nbsp;</td></tr>
</table>
</body>
</html>




2. Example code for create a multi line alert in JavaScript.

JavaScript Code

<script type="text/javascript" language="javascript">

<!--

function lineBreakAlert(){

window.alert("You can display multiple lines in your message\n1.This is the second line\n2.This is third line\nUse \'\\n\' to break lines in your message");

return false;

}

-->

</script>

HTML Code


<html>

<head><title>How to create a multiple line alert </title>

</head><body>

<table border="0"><tr>

<td>&nbsp;<input name="btnmessage" type="submit" id="btnmessage" onclick="javascript:lineBreakAlert();" value="Click Here " /></td>

<td>&nbsp;</td></tr>

</table>

</body>

</html>




3. Example code for create a prompt dialog box in JavaScript.

JavaScript Code

<script type="text/javascript" language="javascript">

<!--

function promptName(){

var name=window.prompt("Please enter your Name","");

if(name==null){

alert("Please enter your name");

return false;

}else{

if(name!=""){

alert("Your Name is "+name);

return false;

}else{

alert("Please enter your name");

return false;

}

}

}

-->

</script>

HTML Code


<html>

<head><title>How to create a multiple line alert </title>

</head><body>

<table border="0"><tr>

<td>&nbsp;<input name="btnmessage" type="submit" id="btnmessage" onclick="javascript:promptName();" value="Click Here " /></td>

<td>&nbsp;</td></tr>

</table>

</body>

</html>




4. Example code for create a confirm dialog box in JavaScript.

JavaScript Code

<script type="text/javascript" language="javascript">

<!--

function simpleConfirm(){

var response=confirm("Click \'Ok\' or \'Cancel\'");

alert("You clicked "+(response==true?"Ok":"Cancel")+" button");



}

-->

</script>

HTML Code


<html>

<head><title>How to create a confirm dialog box </title>

</head><body>

<table border="0"><tr>

<td>&nbsp;<input name="btnmessage" type="submit" id="btnmessage" onclick="javascript:simpleConfirm();" value="Click Here " /></td>

<td>&nbsp;</td></tr>

</table>

</body>

</html>





 »   How to get screen resolution in JavaScript
 »   How to limit characters in textarea using JavaScript
 »   How to validate decimal number in JavaScript
 »   How to validate an email address in JavaScript
 »   How to validate date using JavaScript
 »   JavaScript String functions
 »   How to validate multiple select list box in JavaScript
 »   How to generate random numbers in JavaScript
 »   How to validate multiple check box in JavaScript
 »   How to validate user login in JavaScript
 »   How to validate drop down list in JavaScript
 »   How to validate radio button group in JavaScript
 »   How to create JavaScript alerts
 »    How to create popup windows in JavaScript
 »   How to count words in a text area using JavaScript




©-Copyright By Duminda Chamara   
JavaScript Validation  

14 comments:

Garrick Co Ida said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from javascript and jquery training in chennai . or learn thru Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. javascript and jquery training in chennai

Pavel Co Ebele said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai

Juliana Kho said...


1
2
3
4
5
6 osg777 download
7
8

mahil said...

Excellent post...! It is a very great idea and unique content. Thank you so much...
Excel Training in Chennai
Excel Advanced course
Unix Training in Chennai
Linux Training in Chennai
Graphic Design Courses in Chennai
Tableau Training in Chennai
Pega Training in Chennai
Primavera Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Power BI Training in Chennai
Appium Training in Chennai

Devi said...

Very nice informative blog. Actually it's great article. Thanks for sharing unique content. oracle training in chennai

siva said...

Your post is really good. It is really helpful for me to improve my knowledge in the right way..
benefits of seo
correct pronunciation of english words
web design articles
selenium testing tool
salesforce integration interview questions
salesforce interview questions for experienced

Aishwariya said...

Awesome post. Woderful content. I am regularly follow this blog. Thank you for updating such a good content. Amazon Web Services Training in Chennai

ram said...

Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Do check them out
Best Data training in chennai & get to know everything you want to about software trainings.

Devi said...

Infycle Technologies offers the best Data Science Certification in Chennai and is widely known for its excellence in giving the best Data Science training in Chennai. Providing quality software programming training with 100% placement & to build a solid career for every young professional in the software industry is the ultimate aim of Infycle Technologies. Apart from all, the students love the 100% practical training, which is the specialty of Infycle Technologies. To proceed with your career with a solid base, reach Infycle Technologies through 7502633633.Get Data Science Certification in Chennai | Infycle Technologies

Aishwariya said...

I read this article. I think You have put a lot of effort to create this article. I appreciate your work.
Thank you much more for sharing with us...!
Reactjs Training in Chennai |
Best Reactjs Training Institute in Chennai |
Reactjs course in Chennai

tech said...

I was unable to oppose remarking. Totally composed! best interiors

nive said...

excellent article....
Ai Course in coimbatore | Machine Learning Course in Coimbatore | placement training institutes in coimbatore | job oriented courses in coimbatore | mean stack training in coimbatore | php Training in coimbatore | digital marketing training in coimbatore | ethical hacking training in coimbatore | Final Year Project Center in Coimbatore | React js training in coimbatore

Devi said...

Infycle Technologies, one of the best software training institutes in Chennai offers excellent Oracle PLSQL training in Chennai for freshers and students, and Tech Professionals of any field. Other demanding courses such as Java, Hadoop, Selenium, Big Data, Android, and iOS Development will also be trained with complete hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7504633633 to get more info and a free demo.Excellent Oracle PLSQL Training Chennai | Infycle Technologies

Unknown said...

Infycle Technologies, the No.1 software training institute in Chennai offers the Selenium course in Chennai for tech professionals, freshers, and students at the best offers. In addition to the Selenium, other in-demand courses such as Python, Big Data, Oracle, Java, Python, Power BI, Digital Marketing, Cyber Security also will be trained with hands-on practical classes. After the completion of training, the trainees will be sent for placement interviews in the top companies. Call 7504633633 to get more info and a free demo.