In: Computer Science
6. What does the XXXXX need to be replaced with to trigger the function in the following code when the submit button is pressed:
<form XXXXX="submitIt()"> Enter name: <input type="text"> <input type="submit"> </form>
<input type="number" name="quantity" >
Rewrite the HTML code above using the required attribute to let the input accept only a number from 1 to 20.
Country code: <input type="text" name="country_code" XXXXXX="[A-Za-z]{3}" title="Three letter country code">
Rewrite the HTML code above substituting XXXXX with the attribute name that lets the input accept only 3 alphabetic characters:
Username: <input type="text" name="usrname" XXXXX>
Rewrite the HTML code above substituting XXXXX with the attribute name that tells the Web page to check the presence of a value before the HTML form can be submitted:
Country <input type="text" name="country" value="USA" XXXXX>
Rewrite the HTML code above substituting XXXXX with the attribute name that prevents user from typing data into the text input:
<script> function myFunction() { var inpObj = document.getElementById("id1"); if (!inpObj.XXX()) { document.getElementById("demo").innerHTML = inpObj.validationMessage; } else { document.getElementById("demo").innerHTML = "Input OK"; } } </script> <p>Enter a number and click OK:</p> <input id="id1" type="number" min="100" max="300" required> <button onclick="myFunction()">OK</button> <p>If the number is less than 100 or greater than 300, an error message will be displayed.</p> <p id="demo"></p>
function validateForm() { var x = document.forms["myForm"]["fname"].value; if (XXX) { alert("Name must be filled out"); return false; }
}
<p id="demo"></p> <script> ????? = "Hello"; </script>
Here is anwers of all of your qestions, Please hit that like or thumbs-up button<3
All the values of XXX is in fornt of Answer as well as in your code which is in Bold format.
Q1 )
Answer : - action
<form action="submitIt()"> Enter name: <input type="text"> <input type="submit"> </form>
Q2)
Answer : - onKeyPress="if(this.value.length>20) return false;"
Alternative : - min="1" max="20"
<input type="number" name="quantity" onKeyPress="if(this.value.length>20) return false;">
Alternative : - <input type="number" name="quantity" min="1" max="20">
Q3)
Answer :- pattern
Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
Q4)
Answer: required
Username: <input type="text" name="usrname" required>
Q5)
Answer: disabled
Country <input type="text" name="country" value="USA" disabled>
Q6)
Answer : - checkValidity()
<script> function myFunction() { var inpObj = document.getElementById("id1"); if (!inpObj.checkValidity()) { document.getElementById("demo").innerHTML = inpObj.validationMessage; } else { document.getElementById("demo").innerHTML = "Input OK"; } } </script>
Q7)
Answer :- x == ""
function validateForm() { var x = document.forms["myForm"]["fname"].value; if (x == "") { alert("Name must be filled out"); return false; }
}
Q8) Suppose there is an input element to contain a birthday. What is the correct HTML code to specify that the birthday value cannot be earlier than Jan 1, 1900.
Answer: - <input type="birthdate" id="myDate" name="bday" min="1900-01-01">
Q9) Suppose there is an input number that can only contain even values, positive or negative (-4, -2, 0, 2,) What is the correct HTML syntax for validation
Answer : - <input type="number" pattern="^(\s*\d*[02468]\s*,)*(\s*\d*[-2-4-6-8]\s*)$">
Q10) Write a JavaScript function that has two arguments, multiplies them and returns the result. Invoke the function and then print the result using alert.
Answer: -
<script>
function myFunction() {
var y = 6;
var z = 6;
var x = y * z;
alert("The Result is " + x);
}
</script>
Q11) Use the getElementById method to find the <p> element, and change its text to "Hello":
Answer : -
<p id="demo"></p> <script> document.getElementById("demo").innerHTML="Hello"; </script>
Please do not forget to appreciate my work by hitting that like or thumbs-up button, it really motivates me<3
Thank you!!