0
<html>
<body>

Enter your firstname <input type="text" fname="submit">
Enter your lastname <input type="text" lname="submit">

<html>
<head>




<script type="text/javascript">
if(submit(lname==null))

{
alert(" be careful");
}
 
 
</script> 
</head>

<input type="submit"   onclick="submit()"
value="Submit" style="color:white; background-color:red;">

i need help with writing if loop for submit button an alert message that show we forgot to input name when click on submit button

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Taywin
0

try this one, but javaAddict is right, better study.

<html>
<head>
<script type="text/javascript">
function alertMessage(firstName) {
    if(firstName == "") {
        alert('Empty String');
    }
}
</script>
</head>
<body>
<label>Enter your firstname</label><input type="text" name="txtFirstName" id="txtFirstName"/>
<br />
<label>Enter your lastname</label><input type="text" name="txtLastName" id="txtLastName"/>
<br />
<input type="button" value="Validate" onclick="alertMessage(txtFirstName.value)"/>
</body>
</html>

Edited by Reverend Jim: Fixed formatting

0

Both javaAddict and Iambing are correct. One more suggestion is that you should not heavily rely on w3schools website because certain information on that site is outdated. Just use Google if whatever on that site does not work for you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.