Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Page Layout</title>
- <!--
- The number of lines that can be printed on a paper depends on the paper size,
- the point size of each character in a line, whether lines are double-spaced or
- single-spaced, the top and bottom margin, and the left and right margins of the
- paper. Assume that all characters are of the same point size, and all lines are either
- single-spaced or double-spaced. Note that 1 inch=72 points. Moreover, assume that the
- lines are printed along the width of the paper. For example, if the length of the paper
- is 11 inches and width is 8.5 inches, then the maximum length of a line is 8.5 inches.
- Write a program that calculates the number of characters in a line and the number of lines
- that can be printed on a paper based on the following input from the user:
- a. The lenght and width, in inches of the paper
- b. The top, bottom, left and right margins
- c. The point size of a line
- d. If the lines are double-spaced, then double the point size of each character
- -->
- <script type="text/javascript">
- function elid(id){
- return document.getElementById(id);
- }
- function formFloat(id){
- var input = elid(id).value;
- var num = parseFloat(input);
- if(input != num){
- alert(id.substr(0,1).toUpperCase() + id.substr(1) + ' needs to be a number');
- errors++;
- return false;
- }else{
- return num;
- }
- }
- function Calculate(){
- errors = 0;
- var width = formFloat('width');
- var length = formFloat('length');
- var top = formFloat('top');
- var bottom = formFloat('bottom');
- var left = formFloat('left');
- var right = formFloat('right');
- var font = formFloat('font');
- var spacing = formFloat('spacing');
- if(errors === 0){
- var hMar = left + right;
- var vMar = top + bottom;
- var hSpace = width - hMar;
- var vSpace = length - vMar;
- var charsPerLine = Math.floor(hSpace / (font/72));
- var linesPerPage = Math.floor(vSpace / ((font/72) * spacing));
- var charsPerPage = charsPerLine * linesPerPage;
- }else{
- var charsPerLine = linesPerPage = charsPerPage = 'Errors In The Input';
- }
- elid("cline").value = charsPerLine;
- elid("lpage").value = linesPerPage;
- elid("cpage").value = charsPerPage;
- }
- var errors = 0;
- </script>
- </head>
- <body>
- <form id='frm'>
- <table border="0">
- <tr>
- <th colspan="2"> Paper Size (inches)</th>
- </tr>
- <tr>
- <td> Width</td>
- <td><input type="text" id="width"></td>
- </tr>
- <tr>
- <td> Length</td>
- <td> <input type="text" id="length"></td>
- </tr>
- <tr>
- <th colspan=2> Margins (inches) </th>
- </tr>
- <tr>
- <td> Top </td>
- <td> <input type="text" id="top"></td>
- </tr>
- <tr>
- <td> Bottom </td>
- <td> <input type="text" id="bottom"></td>
- </tr>
- <tr>
- <td> Left </td>
- <td> <input type="text" id="left"></td>
- </tr>
- <tr>
- <td> Right </td>
- <td> <input type="text" id="right"></td>
- </tr>
- <tr>
- <th colspan=2> Formatting </th>
- </tr>
- <tr>
- <td> Font Size (pt) </td>
- <td> <input type="text" id="font"></td>
- </tr>
- <tr>
- <td> Line Spacing </td>
- <td>
- <select id="spacing">
- <option value="1" selected> Single </option>
- <option value="2"> Double </option>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan=2><center> <input type="button" value="Calculate" onclick="Javascript: Calculate();"> </center> </td>
- </tr>
- </table>
- <br><br>
- <table border="0">
- <tr>
- <td> No. of Characters in a Line </td>
- <td> <input type="text" id="cline"> </td>
- </tr>
- <tr>
- <td> No. of Lines on a Page </td>
- <td> <input type="text" id="lpage"> </td>
- </tr>
- <tr>
- <td> Characters per Page</td>
- <td> <input type="text" id="cpage"> </td>
- </tr>
- </table>
- </form>
- </body>
- <html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement