1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> <style> table,td,th{ border: 1px solid black ; border-collapse: collapse; } </style> </head> <body> <table> </table> <script> var students = [[1,"Arbind","bim"],[1,"bishal","bhm"],[1,"raju","csit"],[1,"ram","bbm"],[1,"sam","bbm"]] var table=`` table+=`<tr> <th>roll</th> <th>name</th> <th>faculty</th> </tr>` for(var i = 0 ; i < students.length;i++){ table+=`<tr> <td>${students[i][0]}</td> <td>${students[i][1]}</td> <td>${students[i][2]}</td> </tr>` } var data = document.querySelector("table") data.innerHTML=table </script> </body> </html> |
Q.NO 12) javaScript code to check if the given number is multiple of 5 or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <form> Enter the number : <input type="text" name="number" id="number"> <button>check</button> </form> <script> var button = document.querySelector("button") button.addEventListener('click',(e)=>{ e.preventDefault() var number = parseInt(document.getElementById('number').value) if(number%5==0)alert("It is the multiple of 5") else alert("It is not the multiple of 5") }) </script> </body> </html> |
Q.NO 14) HTML code to generate the following table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <style> table,td{ border:1px solid black; border-collapse: collapse; padding:20px; } </style> <body> <table> <tr> <td></td> <td rowspan="2"></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> </table> </body> </html> |
Q.NO 16 ) Example to show client side validation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <form> username : <input type="text" name="username" id="username"> <br> password : <input type="text" name="password" id="password"> <br> contact : <input type="text" name="contact" id="contact"> <br> <button name="submit" id="submit">submit</button> </form> <script> var button = document.querySelector("#submit") button.addEventListener('click',(e)=>{ e.preventDefault() var username= document.getElementById('username').value var password= document.getElementById('password').value var contact= document.getElementById('contact').value var usernameRegex =/^([a-zA-Z])+([0-9]?)+$/ var passwordRegex = /^[A-Za-z0-9]{6}$/ var contactRegex = /^([0-9]){10}$/ if(username.match(usernameRegex) && password.match(passwordRegex) && contact.match(contactRegex)) alert('success') else alert('fail') }) </script> </body> </html> |