[Go to site: main page, start]

0% found this document useful (0 votes)
30 views46 pages

Disable Button with JavaScript

The document contains code snippets demonstrating various ways to manipulate elements and content on a web page using JavaScript and HTML. This includes updating text when input is entered, changing styles on click, retrieving element values, toggling visibility, writing the last modified date, removing select options, and validating form inputs with functions.

Uploaded by

Rocky Ranjan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views46 pages

Disable Button with JavaScript

The document contains code snippets demonstrating various ways to manipulate elements and content on a web page using JavaScript and HTML. This includes updating text when input is entered, changing styles on click, retrieving element values, toggling visibility, writing the last modified date, removing select options, and validating form inputs with functions.

Uploaded by

Rocky Ranjan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

When text input inside the textbox it will display on thye body of webpage…….

<html>

<head>

<script>

function abc()

a=[Link]("abc").value;

[Link]("xyz").innerHTML=a;

</script>

</head>

<input type=input maxlength=40 value="text" id="abc">

<p id="xyz"></p>

</html>

…………………………

Click on the button text color is changed…….

<html>

<head>

<script>

function abc()

x=[Link]("demo");

[Link]="red";

</script>
</head>

<body>

<p id="demo">hi</p>

<button type=button >

</body>

</html>

……………………

<!DOCTYPE html>

<html>

<head>

<script>

function getValue()

  {

  var x=[Link]("myHeader");

  alert([Link]);

  }

</script>

</head>

<body>

<h1 id="myHeader" me!</h1>

</body>

</html>

…………………….
<!DOCTYPE html>

<html>

<body>

<p id="p1">

This is a text.

This is a text.

This is a text.

</p>

<input type="button" value="Hide text"

>

<input type="button" value="Show text"

>

</body>

</html>

…………………………..

<!DOCTYPE html>

<html>

<body>

This document was last modified on:

<script>
[Link]([Link]);

</script>

</body>

</html>

……………………

<!DOCTYPE html>

<html>

<head>

<script>

function removeOption()

var x=[Link]("mySelect");

[Link]([Link]);

</script>

</head>

<body>

<form>

<select id="mySelect">

<option>Apple</option>

<option>Pear</option>

<option>Banana</option>

<option>Orange</option>
</select>

<input type="button" value="Remove selected option">

</form>

</body>

</html>

…………………………

<!DOCTYPE html>

<html>

<body>

<h1 id="id1">My Heading 1</h1>

<button type="button"

>

Click Me!</button>

</body>

</html>

…………………….

<!DOCTYPE html>

<html>

<body>

<h1 on this text!</h1>


</body>

</html>

……………………

<!DOCTYPE html>

<html>

<body>

<h1 on this text!</h1>

</body>

</html>

……………………..

<!DOCTYPE html>

<html>

<body>

<form>

Buttons:

<input type="button" id="btn01" value="OK">

</form>

<p>Click the button below to disable the button above.</p>

<button button</button>


<script>

function disableElement()

[Link]("btn01").disabled=true;

</script>

</body>

</html>

………………………….

<html>

<head>

<script>

function validate()

x=[Link]

at=[Link]("@")

if (at == -1)

alert("Not a valid e-mail")

return false

</script>
</head>

<body>

<form name="myForm" action="[Link]" validate()">

Enter your E-mail:

<input type="text" name="email" size="20">

<input type="submit" value="Submit">

</form>

</body>

</html>

………………………….

<html>

<head>

<script>

function validate()

x=[Link]

input=[Link]

if ([Link]>5)

alert("The field cannot contain more than 5 characters!")

return false

else

{
return true

</script>

</head>

<body>

<form name="myForm" action="[Link]" validate()">

<input type="text" name="myInput" size="20">

<input type="submit" value="Submit">

</form>

</body>

</html>

………………………………………………

<html>

<head>

<script>

function getText()

var x=[Link]("mySelect");

alert([Link][[Link]].text);

</script>

</head>
<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>

<option>Pineapple</option>

<option>Banana</option>

</select>

<br /><br />

<input type="button" value="Show text of selected

fruit">

</form>

</body>

</html>

………………………..

<!DOCTYPE html>

<html>

<body>

<p id="demo">Click the button to change the text in this paragraph.</p>

<button > <script>

function myFunction()

[Link]("demo").innerHTML="Hello World";

};

</script>

</body>

</html>

………………….

<!DOCTYPE html>

<html>

<body>

<p id="demo">Click the button to display todays day of the month.</p>

<button >

<script>

function myFunction()

var d = new Date();


var x = [Link]("demo");

[Link]=[Link]();

</script>

</body>

</html>

……………………………

<!DOCTYPE html>

<html>

<head>

<script>

var myWindow;

function openWin()

myWindow = [Link]("","myWindow","width=400,height=200");

function closeWin()

if (myWindow)

[Link]();
}

function checkWin()

if (!myWindow)

[Link]("msg").innerHTML="'myWindow' has never been opened!";

else

if ([Link])

[Link]("msg").innerHTML="'myWindow' has been closed!";

else

[Link]("msg").innerHTML="'myWindow' has not been closed!";

</script>

</head>

<body>
<button "myWindow"</button>

<button "myWindow"</button>

<br><br>

<button "myWindow" been closed?</button>

<br><br>

<div id="msg"></div>

</body>

</html>

………………………….

<script type="text/javascript">

function changeColor(){

var newColor = [Link]('colorPicker').value;

[Link]('colorMsg').[Link] = newColor;

</script>

<div id="colorMsg" style="font-size:18px;width:150px;height:100px;padding:5px;">Choose a

background color...</div>

<select id="colorPicker" >

<option value="transparent">None</option>

<option value="yellow">Yellow</option>

<option value="salmon">Salmon</option>
<option value="lightblue">Light Blue</option>

<option value="limegreen">Lime Green</option>

</select>

………………………………………..

<script type="text/javascript">

function showMsg(){

var userInput = [Link]('userInput').value;

[Link]('userMsg').innerHTML = userInput;

</script>

<input type="input" maxlength="40" id="userInput" value="Enter text here..." />

<p id="userMsg"></p>

……………………………..

When text input inside the textbox it will display on thye body of webpage…….

<html>

<head>

<script>

function abc()

a=[Link]("abc").value;
[Link]("xyz").innerHTML=a;

</script>

</head>

<input type=input maxlength=40 value="text" id="abc">

<p id="xyz"></p>

</html>

…………………………

Click on the button text color is changed…….

<html>

<head>

<script>

function abc()

x=[Link]("demo");

[Link]="red";

</script>

</head>

<body>

<p id="demo">hi</p>

<button type=button >

</body>

</html>

………………
<!DOCTYPE html>

<html>

<head>

<script>

function getValue()

  {

  var x=[Link]("myHeader");

  alert([Link]);

  }

</script>

</head>

<body>

<h1 id="myHeader" me!</h1>

</body>

</html>

…………………….

<!DOCTYPE html>

<html>

<body>

<p id="p1">

This is a text.

This is a text.
This is a text.

</p>

<input type="button" value="Hide text"

>

<input type="button" value="Show text"

>

</body>

</html>

…………………………..

<!DOCTYPE html>

<html>

<body>

This document was last modified on:

<script>

[Link]([Link]);

</script>

</body>

</html>

……………………

<!DOCTYPE html>
<html>

<head>

<script>

function removeOption()

var x=[Link]("mySelect");

[Link]([Link]);

</script>

</head>

<body>

<form>

<select id="mySelect">

<option>Apple</option>

<option>Pear</option>

<option>Banana</option>

<option>Orange</option>

</select>

<input type="button" value="Remove selected option">

</form>

</body>

</html>

…………………………
<!DOCTYPE html>

<html>

<body>

<h1 id="id1">My Heading 1</h1>

<button type="button"

>

Click Me!</button>

</body>

</html>

…………………….

<!DOCTYPE html>

<html>

<body>

<h1 on this text!</h1>

</body>

</html>

……………………

<!DOCTYPE html>

<html>

<body>
<h1 on this text!</h1>

</body>

</html>

……………………..

<!DOCTYPE html>

<html>

<body>

<form>

Buttons:

<input type="button" id="btn01" value="OK">

</form>

<p>Click the button below to disable the button above.</p>

<button button</button>

<script>

function disableElement()

[Link]("btn01").disabled=true;

}
</script>

</body>

</html>

………………………….

<html>

<head>

<script>

function validate()

x=[Link]

at=[Link]("@")

if (at == -1)

alert("Not a valid e-mail")

return false

</script>

</head>

<body>

<form name="myForm" action="[Link]" validate()">

Enter your E-mail:

<input type="text" name="email" size="20">

<input type="submit" value="Submit">

</form>
</body>

</html>

………………………….

<html>

<head>

<script>

function validate()

x=[Link]

input=[Link]

if ([Link]>5)

alert("The field cannot contain more than 5 characters!")

return false

else

return true

</script>

</head>

<body>
<form name="myForm" action="[Link]" validate()">

<input type="text" name="myInput" size="20">

<input type="submit" value="Submit">

</form>

</body>

</html>

………………………………………………

<html>

<head>

<script>

function getText()

var x=[Link]("mySelect");

alert([Link][[Link]].text);

</script>

</head>

<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>

<option>Pineapple</option>
<option>Banana</option>

</select>

<br /><br />

<input type="button" value="Show text of selected

fruit">

</form>

</body>

</html>

………………………

<html>

<head>

<script>

function padding()

[Link]('mytable').cellPadding="15";

function spacing()

[Link]('mytable').cellSpacing="15";

</script>

</head>

<body>
<table id=mytable border=1>

<tbody>

<tr>

<td>100</td>

<td>200</td></tr>

<tr>

<td>300</td>

<td>400</td></tr></tbody></table>

<form>

<input type=button value="Change Cellpadding">

<input type=button value="Change Cellspacing">

</form></body></html>

…………………….

<html>

<head>

<script>

function formSubmit()

[Link]()

</script>

</head>

<body>

<form name="myForm" action="[Link]" method="get">

Firstname: <input type="text" name="firstname" size="20"><br>


Lastname: <input type="text" name="lastname" size="20"><br><br>

<input type="button" value="Submit">

</form>

</body>

</html>

……………………

<html>

<head>

<script>

function formAction()

var x=[Link]("mySelect");

[Link]=true;

</script>

</head>

<body>

<form>

<select name="mySelect" size="3">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

</select>
<input type="button" value="Select multiple">

</form>

</body>

</html>

……………………

<html>

<head>

<script>

function formAction()

var x=[Link]("mySelect");

alert([Link]);

</script>

</head>

<body>

<form name="ashish">

<select id="mySelect">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

</select>

<input type="button" value="Show">


</form>

</body>

</html>

………………………..

<html>

<body>

<script type="text/javascript">

[Link]("<p>Browser: ")

[Link]([Link] + "</p>")

[Link]("<p>Browserversion: ")

[Link]([Link] + "</p>")

[Link]("<p>Code: ")

[Link]([Link] + "</p>")

[Link]("<p>Platform: ")

[Link]([Link] + "</p>")

[Link]("<p>Cookies enabled: ")

[Link]([Link] + "</p>")

[Link]("<p>Browser's user agent header: ")


[Link]([Link] + "</p>")

</script>

</body>

</html>

……………………….

<html>

<head>

<script type="text/javascript">

function formAction()

var x=[Link]("mySelect")

[Link]="3"

</script>

</head>

<body>

<form>

<select name="mySelect">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

<option>Melon</option>

</select>

<input type="button" value="Change size of list">


</form>

</body>

</html>

………………………

<html>

<head>

<script type="text/javascript">

function formAction()

var x=[Link]("mySelect")

[Link]([Link])

</script>

</head>

<body>

<form>

<select name="mySelect">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

</select>

<input type="button" value="Remove option">

</form>
</body>

</html>

……………………..

<html>

<head>

<script type="text/javascript">

function changeText()

var x=[Link]("mySelect")

[Link][[Link]].text="Melon"

</script>

</head>

<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>

<option>Pineapple</option>

<option>Banana</option>

</select>

<br /><br />


<input type="button" value="Change text of selected fruit">

</form>

</body>

</html>

…………………………..

<html>

<head>

<script type="text/javascript">

function getIndex()

var x=[Link]("mySelect")

alert([Link])

</script>

</head>

<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>

<option>Pineapple</option>

<option>Banana</option>
</select>

<br /><br />

<input type="button" value="Show index of selected fruit">

</form>

</body>

</html>

………………..

<html>

<body>

hi [Link] [Link] [Link] [Link] [Link] [Link] [Link]


[Link] [Link] [Link] [Link] [Link] [Link] [Link]
[Link] [Link] [Link] [Link] [Link] [Link] [Link]
[Link] [Link] [Link] [Link] [Link] [Link] [Link]
[Link] everybody.

<script>

if ([Link]) {

[Link]('<form><input type=button name=print value="Print"


>

</script>

</body>

</html>

…………………………………

<!DOCTYPE html>

<html>

<body>
<p id="demo">Click the button to change the text in this paragraph.</p>

<button >

<script>

function myFunction()

[Link]("demo").innerHTML="Hello World";

};

</script>

</body>

</html>

………………….

<!DOCTYPE html>

<html>

<body>

<p id="demo">Click the button to display todays day of the month.</p>

<button > <script>

function myFunction()

var d = new Date();

var x = [Link]("demo");

[Link]=[Link]();

</script>

</body>

</html>

……………………………

<!DOCTYPE html>

<html>

<head>

<script>

var myWindow;

function openWin()

myWindow = [Link]("","myWindow","width=400,height=200");

function closeWin()
{

if (myWindow)

[Link]();

function checkWin()

if (!myWindow)

[Link]("msg").innerHTML="'myWindow' has never been opened!";

else

if ([Link])

[Link]("msg").innerHTML="'myWindow' has been closed!";

else

[Link]("msg").innerHTML="'myWindow' has not been closed!";

}
</script>

</head>

<body>

<button "myWindow"</button>

<button "myWindow"</button>

<br><br>

<button "myWindow" been closed?</button>

<br><br>

<div id="msg"></div>

</body>

</html>

………………………….

<html>

<head>

<script type="text/javascript">

function specifyRow()

var x=[Link]('myTable').rows

x[2].height="100"

</script>

</head>
<body>

<table id="myTable" border="1">

<tr>

<td>Row1 cell1</td>

<td>Row1 cell2</td>

</tr>

<tr>

<td>Row2 cell1</td>

<td>Row2 cell2</td>

</tr>

<tr>

<td>Row3 cell1</td>

<td>Row3 cell2</td>

</tr>

<tr>

<td>Row4 cell1</td>

<td>Row4 cell2</td>

</tr>

<tr>

<td>Row5 cell1</td>

<td>Row5 cell2</td>

</tr>

</table>

<form>
<input type="button" value="Change height of third row">

</form>

</body>

</html>

…………………………

<html>

<head>

<script type="text/javascript">

function getText()

var x=[Link]("mySelect")

alert([Link][[Link]].text)

</script>

</head>

<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>

<option>Pineapple</option>

<option>Banana</option>
</select>

<br /><br />

<input type="button" value="Show text of selected fruit">

</form>

</body>

</html>

…………………

<html>

<head>

<script type="text/javascript">

function changeText()

var x=[Link]("mySelect")

[Link][[Link]].text="Melon"

</script>

</head>

<body>

<form>

Select your favorite fruit:

<select id="mySelect">

<option>Apple</option>

<option>Orange</option>
<option>Pineapple</option>

<option>Banana</option>

</select>

<br /><br />

<input type="button" value="Change text of selected fruit">

</form>

</body>

</html>

………………………

<html>

<head>

<script type="text/javascript">

function makeDisable()

var x=[Link]("mySelect")

[Link]=true

function makeEnable()

var x=[Link]("mySelect")

[Link]=false

</script>

</head>
<body>

<form>

<select id="mySelect">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

</select>

<input type="button" value="Disable list">

<input type="button" value="Enable list">

</form>

</body>

</html>

…………………..

<html>

<head>

<script type="text/javascript">

function formAction()

var x=[Link]("mySelect")

[Link]=true

</script>

</head>
<body>

<p>

Before you click on the "Select multiple" button, try to select more than one option (by holding down
the shift or Ctrl key). Click on the "Select multiple" button and try again.

</p>

<form>

<select name="mySelect" size="3">

<option>Apple</option>

<option>Banana</option>

<option>Orange</option>

</select>

<input type="button" value="Select multiple">

</form>

</body>

</html>

………………………

<html>

<head>

<script>

function show() {

var elem = [Link]("BeatleList");

alert([Link]);

</script>
</head>

<body >

<h1>Rockbands</h1>

<h2>Beatles</h2>

<ol id="BeatleList">

<li>Paul</li>

<li>John</li>

<li>George</li>

<li>Ringo</li>

</ol>

<h2>Rolling Stones</h2>

<ol id="StonesList">

<li>Mick</li>

<li>Keith</li>

<li>Charlie</li>

<li>Bill</li>

</ol>

</body>

</html>

……………………

<html>

<body>

<p>This example calls a function which performs a calculation,and returns the result:</p>

<p id="demo"></p>

<script>
function myFunction(a,b)

return a*b;

[Link]("demo").innerHTML=myFunction(5,5);

</script>

</body>

</html>

…………………….

You might also like