CSS Chapter 3 Notes
CSS Chapter 3 Notes
Example 3.3.2
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example 3.3.2</title>
<script>
function OnSelChange(element){
var selected = element.options[element.selectedIndex].value;
document.getElementById("demo").innerHTML="You have selected :"+selected;
Output:
https://www.javatpoint.com/how-to-get-all-checked-checkbox-value-in-javascript
https://www.tutorialspoint.com/How-to-check-whether-a-checkbox-is-checked-in-
JavaScript#:~:text=In%20JavaScript%2C%20we%20can%20access,on%20the%20checkbox%20i
s%20checked.
https://www.javascripttutorial.net/javascript-dom/javascript-checkbox/
3.6 Changing a label dynamically
We can change the label of the form element dynamically i.e relabeling of form element.
Example 3.6.1
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example 3.6.1</title>
<script>
function updatelist(elevalue)
{
with(document.forms.myform)
{
if(elevalue=="Fruits")
{ togglebtn.value="Vegetables";
oplist[0].text="Mango";
oplist[0].value=1;
oplist[1].text="Apple";
oplist[1].value=2;
oplist[2].text="Banana";
oplist[2].value=3;
document.getElementById("demo").innerHTML="Now you are looking Fruits";
}
if(elevalue=="Vegetables")
{ togglebtn.value="Fruits";
oplist[0].text="Tamato";
https://www.geeksforgeeks.org/how-to-change-the-text-of-a-label-using-javascript/
3.7 Manipulate form elements
JavaScript provide a facility to manipulate form elements after the user clicks the Submit button
and before the form is actually submitted to the application.
Example 3.7.1
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<script>
Prof. Pathan F. S 9 Jamia Polytechnic (0366)
Computer Dept. Akkalkuwa
Client Side Scripting Language : JavaScript
function addmail()
{
with (document.forms.myform)
{
if(fname.value.length>0 && lname.value.length>0)
{
email.value=fname.value.charAt(0)+lname.value+"@gmail.com";
}
}
}
</script>
</head>
<body>
<form action="" name="myform">
First Name = <input type="text" name="fname"><br>
Last Name = <input type="text" name="lname"><br>
Email = <input type="hidden" name="email"><br>
<input type="button" name="submit" value="Submit" onclick="addmail()">
</form>
</body>
</html>
Output :
https://rahultamkhane.medium.com/develop-a-webpage-using-intrinsic-java-functions-
36cb3b84826c
3.8.1 Disabling elements
Some time we need to enable or disable input elements like text box, radio button or checkbox etc.
The element can be disabled by setting disable property to true.
A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray
by default in browsers.
buttonObject.disabled
buttonObject.disabled = true|false
Example 3.8.1a:
<!DOCTYPE html>
<html>
<body>
<button id="myBtn">My Button</button>
<br><br>
<button onclick="disableBtn()">Disable "My Button"</button>
<button onclick="enableBtn()">Enable "My Button"</button>
<script>
function disableBtn() {
document.getElementById("myBtn").disabled = true;
}
function enableBtn() {
document.getElementById("myBtn").disabled = false;
}
</script>
</body>
</html>
Example 3.8.1b:
<!DOCTYPE html>
<html lang="en">
<head>
<script>
function toggle()
{
var txt = document.getElementById("mytxt");
if('disabled' in txt)
{
txt.disabled=!txt.disabled;
txt.value = "Text box is enabled"
}
}
</script>
<title>Example 3.8.2</title>
</head>
<body>
<input type="text" id="mytxt" disabled="disabled" value="Text box is disabled"><br>
<button onclick="toggle();">Change State</button>
</body>
</html>
https://www.geeksforgeeks.org/how-to-add-readonly-attribute-to-an-input-tag-in-javascript/