basic script
<script type="text/javascript">
function enteredText()
{
var txtTypeSomething = document.getElementById("txtTypeSomething");
var spnMessage = document.getElementById("spnMessage");
if(txtTypeSomething.value != "")
{
spnMessage.innerHTML = "You entered " + txtTypeSomething.value + ".";
spnMessage.style.color="green";
}
else
{
spnMessage.innerHTML = "You entered nothing";
spnMessage.style.color="red";
}
}
</script>
function enteredText()
{
var txtTypeSomething = document.getElementById("txtTypeSomething");
var spnMessage = document.getElementById("spnMessage");
if(txtTypeSomething.value != "")
{
spnMessage.innerHTML = "You entered " + txtTypeSomething.value + ".";
spnMessage.style.color="green";
}
else
{
spnMessage.innerHTML = "You entered nothing";
spnMessage.style.color="red";
}
}
</script>
full code
<!doctype html>
<html lang=""en">
<!-- scripting by Serge SEVEAU July 2023-->
<head>
<meta charset="utf-8">
<title>if-then-else</title>
<style type=""text/css>
#ifThenElse /*the # connects style to form with id=ifThenElse*/
{
background-color:rgb(234, 232, 232);
font-family:'Times New Roman';
font-size: 20px; color:black;
padding: 5px;
}
}
</style>
</head>
<body>
<form id="ifThenElse">
<fieldset> <!--creates a rectangular box-->
<legend>If-Then-Else</legend><!--name the rectangular box-->
<br>
<label>Type something:</label>
<input type="text" id="txtTypeSomething" value=""/>
<!--this is to register the input of data-->
<span id="spnMessage"></span><br/><br>
<!--when button clicked, information is saved as enteredText-->
<input type="button" id="userName" value="Button 1" onclick="enteredText()"/>
<!--the end of the rectangular box created-->
</fieldset>
</form>
</body>
<!-- The <span> tag is very similar to the <div> element,
but <div> is a block-level element wheree as <span> is an inline element (and writes
directaly in the document without requiring a label - innerHTML. -->
<script type="text/javascript">
function enteredText()
{
var txtTypeSomething = document.getElementById("txtTypeSomething");
//alert("button clicked");
//alert(txtTypeSomething.value);
var spnMessage = document.getElementById("spnMessage");
if(txtTypeSomething.value != "") //doeas not equal
{
spnMessage.innerHTML = "You entered " + txtTypeSomething.value + ".";
spnMessage.style.color="green";
}
else
{
spnMessage.innerHTML = "You entered nothing"; //innerHTML does not require a label
spnMessage.style.color="red";
}
}
</script>
</html>
<html lang=""en">
<!-- scripting by Serge SEVEAU July 2023-->
<head>
<meta charset="utf-8">
<title>if-then-else</title>
<style type=""text/css>
#ifThenElse /*the # connects style to form with id=ifThenElse*/
{
background-color:rgb(234, 232, 232);
font-family:'Times New Roman';
font-size: 20px; color:black;
padding: 5px;
}
}
</style>
</head>
<body>
<form id="ifThenElse">
<fieldset> <!--creates a rectangular box-->
<legend>If-Then-Else</legend><!--name the rectangular box-->
<br>
<label>Type something:</label>
<input type="text" id="txtTypeSomething" value=""/>
<!--this is to register the input of data-->
<span id="spnMessage"></span><br/><br>
<!--when button clicked, information is saved as enteredText-->
<input type="button" id="userName" value="Button 1" onclick="enteredText()"/>
<!--the end of the rectangular box created-->
</fieldset>
</form>
</body>
<!-- The <span> tag is very similar to the <div> element,
but <div> is a block-level element wheree as <span> is an inline element (and writes
directaly in the document without requiring a label - innerHTML. -->
<script type="text/javascript">
function enteredText()
{
var txtTypeSomething = document.getElementById("txtTypeSomething");
//alert("button clicked");
//alert(txtTypeSomething.value);
var spnMessage = document.getElementById("spnMessage");
if(txtTypeSomething.value != "") //doeas not equal
{
spnMessage.innerHTML = "You entered " + txtTypeSomething.value + ".";
spnMessage.style.color="green";
}
else
{
spnMessage.innerHTML = "You entered nothing"; //innerHTML does not require a label
spnMessage.style.color="red";
}
}
</script>
</html>
🌳 👍 🤣 🎶 💩