Monday, 16 September 2024

WRITE A JAVASCRIPT TO READ CHARACTER AND PRINT MALE OR FEMALE OR INVALID CHARACTER

 <!DOCTYPE html>

<html>

<body>

<h2> Read a character and print Male or Female based on M or F and otherwise "Invalid Character". </h2>


<table border="2px">

<tr>

<th>Enter character: </th>

<td><input type="text" name="txt_string" id="charecter" maxlength="1" size="1"/></td>

</tr>

<tr>

<td colspan="2" align="center">

<input type="submit" value="click me" onclick="findMale()"/></td>

</tr>

</table>

<script language="JavaScript">

function findMale() {

var ch = document.getElementById("charecter").value;

if(ch == "M" || ch == "m") {

document.write("You have entered: "+ch+" "+"is Male.");

}

else if(ch == "F" || ch == "f") {

document.write("You have entered: "+ch+" "+"is Female.");

}

else {

document.write("You have entered: "+ch+" "+" which is invalid choice.");

}

}

</script>


</body>

</html>


No comments:

Post a Comment