<html>
<head>
<title></title>
</head>
<body>
<input type="text" name="t1" id="t1">
<input type="button" value="Submit" onclick="show_prime()">
<div id=d1></div>
<script type="text/javascript">
function show_prime(){
x=document.getElementById("t1").value
x=parseInt(x)
if(Number.isInteger(x)){
str='';
for (i=2;i<x;i++){
flag=0;
for(j=2;j<i;j++){
if(i%j == 0){
flag=1;
break;
}
}
if(flag==0){
str= str + i + ","
}
}
document.getElementById('d1').innerHTML="Series is : " + str
}else{
document.getElementById('d1').innerHTML="Enter an Integer "
}
}
</script>
</body>
</html>
| isInteger() | Checking if input number is integer or not |
| parseInt() | function to convert string to number |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.