<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

First check some html and javascript tutorials because that code is totally wrong. It needs to rewritten from the beginning.
I would suggest this:
http://www.w3schools.com/default.asp
First learn about html and then move to javascript

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>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.