View Full Version : Naming an alert

10-22-2005, 05:03 AM
Ok i want to name an alert so that It can be called upon without being in a function. Code is as follows:

Sign In page

<script type="text/javascript">

function AccessText()

return document.getElementById("FirstName")


<script type="text/javascript">

window.alert("Welcome, "+document.getElementById("FirstName")+" you are signed in")




<input type="text" id="FirstName" value="Enter your first name">
<input type="button" value="Sign In" onclick="">



OK so how would I assign the window.alert a name?? So that I can access it with the onclick feature? Thank you.

Philip M
10-22-2005, 08:02 AM
You can't. OK?

Mr J
10-22-2005, 12:24 PM
Why not simply go

onclick="alert('Hello World')"

or put it in a function

function myClick(){

alert("Hello World)



10-22-2005, 12:37 PM
Edit: Posted at same time as MrJ!

no need to name alerts - it is native code of all javascript engines. Also there's no need to call an alert explicitly through the window object:
window.alert("hello world");Can be referenced more cleanly as:
alert("hello world");You can drop the call directly into your onclick event (note the use of single quote marks within the html onclick attribute):
<input type="button" value="Sign In" onclick="alert('Welcome '+document.getElementById('FirstName')+' you are signed in');">This is much better run as a function however as validation is needed:
function doAlert() {
var el = document.getElementById("FirstName");
if(el.value.length == 0) {
alert("Please enter your first name");
} else {
alert("Welcome "+el.value+" you are signed in");

// Your html button:
<input type="button" value="Sign In" onclick="doAlert();">Hope this helps