SlideShare a Scribd company logo
Implement a Javascript application that allows the user to enter strings into a variable number of
input widgets. As a string is entered by the user its length is automatically displayed next to the
input widget. Buttons are provided to control the interface and to provide some functionality. .
Clicking one button will add another input widget Clicking another button will remove an input
widget, always leaving at least one input widget. . Clicking anther button will cause the visible
strings to be sorted As a convenience to the user, the application will remember the string
entered into a widget even after the widget is removed. If the widget is added back again, then
the saved value will be displayed in the widget. But, be careful, the saved strings do not
participate in a sort operation if not visible. Provide styling that will approximately center the
visible components. Also, change the default color for the background. Organize the application
in three files: the HTML file that is the user interface to the application; a file with most of the
Javascript code; a file with the styling rules.
Solution
<HTML>
<HEAD>
<TITLE> My Program in Java Script </TITLE>
<SCRIPT language="javascript">
function addNewRow(tableID) {
var table = document.getElementById(tableID);
var count_row = table.rows.length;
var row = table.insertRow(count_row);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name="check_box[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
cell2.innerHTML = count_row + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "txtbox[]";
cell3.appendChild(element2);
}
function deletePreviousRow(tableID) {
try {
var table = document.getElementById(tableID);
var count_row = table.rows.length;
for(var i=0; i<count_row; i++) {
var row = table.rows[i];
var check_box = row.cells[0].childNodes[0];
if(null != check_box && true == check_box.checked) {
table.deletePreviousRow(i);
count_row--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Add Row" onclick="addNewRow('myTable')" />
<INPUT type="button" value="Delete Row" onclick="deletePreviousRow('myTable')" />
<TABLE id="myTable" width="350px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD> 1 </TD>
<TD> <INPUT type="text" /> </TD>
</TR>
</TABLE>
</BODY>
</HTML>

More Related Content

Similar to Implement a Javascript application that allows the user to enter strin.docx (20)

PDF
lect4
tutorialsruby
 
PDF
lect4
tutorialsruby
 
PPT
Java Script ppt
Priya Goyal
 
PPTX
JavaScript / Web Engineering / Web Development / html + css + js/presentation
M Sajid R
 
PPTX
An introduction to javascript
tonyh1
 
PPTX
introduction to java scriptsfor sym.pptx
gayatridwahane
 
PPT
Javascript
Manav Prasad
 
PPT
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
PDF
Intro to javascript (5:2)
Thinkful
 
PPTX
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
PDF
Intro to javascript (6:19)
Thinkful
 
KEY
Javascript done right - Open Web Camp III
Dirk Ginader
 
PPTX
5 Tips for Better JavaScript
Todd Anglin
 
PPS
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
PPTX
An Introduction to JavaScript
tonyh1
 
PDF
2 coding101 fewd_lesson2_programming_overview 20210105
John Picasso
 
PDF
Designing JS APis
Caio Gondim
 
PDF
Maintainable JavaScript 2011
Nicholas Zakas
 
PPTX
Java Script
Kalidass Balasubramaniam
 
PDF
GDI Seattle - Intro to JavaScript Class 2
Heather Rock
 
Java Script ppt
Priya Goyal
 
JavaScript / Web Engineering / Web Development / html + css + js/presentation
M Sajid R
 
An introduction to javascript
tonyh1
 
introduction to java scriptsfor sym.pptx
gayatridwahane
 
Javascript
Manav Prasad
 
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
Intro to javascript (5:2)
Thinkful
 
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
Intro to javascript (6:19)
Thinkful
 
Javascript done right - Open Web Camp III
Dirk Ginader
 
5 Tips for Better JavaScript
Todd Anglin
 
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
An Introduction to JavaScript
tonyh1
 
2 coding101 fewd_lesson2_programming_overview 20210105
John Picasso
 
Designing JS APis
Caio Gondim
 
Maintainable JavaScript 2011
Nicholas Zakas
 
GDI Seattle - Intro to JavaScript Class 2
Heather Rock
 

More from mckerliejonelle (20)

DOCX
What was ABC Inc's net capital spending in the year 2022- given their.docx
mckerliejonelle
 
DOCX
What subatomic partichis ate located in the nuicleas of an atom- nesif.docx
mckerliejonelle
 
DOCX
what type of decision making style do well in environments where there.docx
mckerliejonelle
 
DOCX
What skills have you gained that would be applied to a computer techno.docx
mckerliejonelle
 
DOCX
What pattern of inheritance does variant have with the RCH gene at the.docx
mckerliejonelle
 
DOCX
What percentage of genetic divergence is used to define separate speci.docx
mckerliejonelle
 
DOCX
What makes Y-C+I+G+NX an identity- Each symbol identifies a variable-.docx
mckerliejonelle
 
DOCX
What motivates radical environmentalist groups like the Earth Liberati.docx
mckerliejonelle
 
DOCX
WHAT IS YOUR CULTURAL INTELLIGENCE- Instructlons- To what extent does.docx
mckerliejonelle
 
DOCX
What is true about the relative concentration of H+ and OH- in water-.docx
mckerliejonelle
 
DOCX
What is the result (in binary) of adding the unsigned char binary numb.docx
mckerliejonelle
 
DOCX
What is the resolution of a digital-to-analog converter (DAC)- It is t.docx
mckerliejonelle
 
DOCX
What is the primary reason that Earth is cold at the poles and hot at.docx
mckerliejonelle
 
DOCX
What is the main differentiating factor of an Advanced Alternative Pay.docx
mckerliejonelle
 
DOCX
What is the main difterence between Al- ML- and OL- Select ones a- ML.docx
mckerliejonelle
 
DOCX
What is the function of helper T cells in cell mediated immunity- Kill.docx
mckerliejonelle
 
DOCX
What is the general FUNCTION of this tissue tvoe- -Pseberbunef that pe.docx
mckerliejonelle
 
DOCX
What is the effect of cholesterol on membrane fluidity at physiologic.docx
mckerliejonelle
 
DOCX
What is the default IP Prefix for a Class A- -16 124 130 18.docx
mckerliejonelle
 
DOCX
What is the biggest animal in the world- What is the only active volca.docx
mckerliejonelle
 
What was ABC Inc's net capital spending in the year 2022- given their.docx
mckerliejonelle
 
What subatomic partichis ate located in the nuicleas of an atom- nesif.docx
mckerliejonelle
 
what type of decision making style do well in environments where there.docx
mckerliejonelle
 
What skills have you gained that would be applied to a computer techno.docx
mckerliejonelle
 
What pattern of inheritance does variant have with the RCH gene at the.docx
mckerliejonelle
 
What percentage of genetic divergence is used to define separate speci.docx
mckerliejonelle
 
What makes Y-C+I+G+NX an identity- Each symbol identifies a variable-.docx
mckerliejonelle
 
What motivates radical environmentalist groups like the Earth Liberati.docx
mckerliejonelle
 
WHAT IS YOUR CULTURAL INTELLIGENCE- Instructlons- To what extent does.docx
mckerliejonelle
 
What is true about the relative concentration of H+ and OH- in water-.docx
mckerliejonelle
 
What is the result (in binary) of adding the unsigned char binary numb.docx
mckerliejonelle
 
What is the resolution of a digital-to-analog converter (DAC)- It is t.docx
mckerliejonelle
 
What is the primary reason that Earth is cold at the poles and hot at.docx
mckerliejonelle
 
What is the main differentiating factor of an Advanced Alternative Pay.docx
mckerliejonelle
 
What is the main difterence between Al- ML- and OL- Select ones a- ML.docx
mckerliejonelle
 
What is the function of helper T cells in cell mediated immunity- Kill.docx
mckerliejonelle
 
What is the general FUNCTION of this tissue tvoe- -Pseberbunef that pe.docx
mckerliejonelle
 
What is the effect of cholesterol on membrane fluidity at physiologic.docx
mckerliejonelle
 
What is the default IP Prefix for a Class A- -16 124 130 18.docx
mckerliejonelle
 
What is the biggest animal in the world- What is the only active volca.docx
mckerliejonelle
 
Ad

Recently uploaded (20)

PPTX
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPTX
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PDF
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PDF
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
PDF
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
Ad

Implement a Javascript application that allows the user to enter strin.docx

  • 1. Implement a Javascript application that allows the user to enter strings into a variable number of input widgets. As a string is entered by the user its length is automatically displayed next to the input widget. Buttons are provided to control the interface and to provide some functionality. . Clicking one button will add another input widget Clicking another button will remove an input widget, always leaving at least one input widget. . Clicking anther button will cause the visible strings to be sorted As a convenience to the user, the application will remember the string entered into a widget even after the widget is removed. If the widget is added back again, then the saved value will be displayed in the widget. But, be careful, the saved strings do not participate in a sort operation if not visible. Provide styling that will approximately center the visible components. Also, change the default color for the background. Organize the application in three files: the HTML file that is the user interface to the application; a file with most of the Javascript code; a file with the styling rules. Solution <HTML> <HEAD> <TITLE> My Program in Java Script </TITLE> <SCRIPT language="javascript"> function addNewRow(tableID) { var table = document.getElementById(tableID); var count_row = table.rows.length; var row = table.insertRow(count_row); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="check_box[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = count_row + 1;
  • 2. var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "txtbox[]"; cell3.appendChild(element2); } function deletePreviousRow(tableID) { try { var table = document.getElementById(tableID); var count_row = table.rows.length; for(var i=0; i<count_row; i++) { var row = table.rows[i]; var check_box = row.cells[0].childNodes[0]; if(null != check_box && true == check_box.checked) { table.deletePreviousRow(i); count_row--; i--; } } }catch(e) { alert(e); } } </SCRIPT> </HEAD> <BODY> <INPUT type="button" value="Add Row" onclick="addNewRow('myTable')" /> <INPUT type="button" value="Delete Row" onclick="deletePreviousRow('myTable')" /> <TABLE id="myTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <INPUT type="text" /> </TD> </TR> </TABLE>