Write a JavaScript/HTML program that inputs two integers a and b

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2008
Posts: 7
Reputation: mibit has a little shameless behaviour in the past 
Solved Threads: 0
mibit mibit is offline Offline
Newbie Poster

Write a JavaScript/HTML program that inputs two integers a and b

 
0
  #1
May 5th, 2009
Write a JavaScript/HTML program that inputs two integers a and b in an input text box, and outputs all odd numbers between
a and b (a and b are expected to be between 1 and 30, and a<b)

Can somebody help me with the source code for the .html file

Thanks a million
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 484
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Write a JavaScript/HTML program that inputs two integers a and b

 
-1
  #2
May 5th, 2009
Your zero interest in subject, brought you to another bad situation and you posted in Java section. Java is NOT JavaScript

Request to move this post to correct section already sent...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,359
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Write a JavaScript/HTML program that inputs two integers a and b

 
0
  #3
May 5th, 2009
So find a JavaScript forum.

Java != JavaScript
Last edited by masijade; May 5th, 2009 at 4:53 am. Reason: Damn! Too slow!
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 7
Reputation: mibit has a little shameless behaviour in the past 
Solved Threads: 0
mibit mibit is offline Offline
Newbie Poster

Re: Write a JavaScript/HTML program that inputs two integers a and b

 
0
  #4
May 5th, 2009
ok you can delete the post please
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Write a JavaScript/HTML program that inputs two integers a and b

 
0
  #5
May 5th, 2009
Try this:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta http-equiv="Content-Style-Type" content="text/css" />
  9. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  10. <title>JavaScript DEMO : Odd Numbers</title>
  11. <style type="text/css">
  12. /* <![CDATA[ */
  13. table {
  14. border : 1px solid #D0D0D0;
  15. border-collapse : collapse;
  16. text-align : left;
  17. width : 70%;
  18. }
  19. td, th {
  20. border-bottom : 1px solid #D0D0D0;
  21. padding : .300em;
  22. }
  23. input[type='text'] {
  24. border-bottom : 2px solid #D0D0D0;
  25. color : #696969;
  26. font-weight : bold;
  27. height : 17px;
  28. text-align : center;
  29. }
  30. /* ]]> */
  31. </style>
  32. <script type="text/javascript">
  33. // <![CDATA[
  34. var result, odds, viaID;
  35. viaID = Boolean( document.getElementBy );
  36. odds = [];
  37. result = function() {
  38. uA = parseInt((( viaID ) ? document.getElementById("unitA").value : document.all.unitA.value ));
  39.  
  40. uB = parseInt((( viaID ) ? document.getElementById("unitB").value : document.all.unitB.value ));
  41.  
  42. oLen = Math.max( uA, uB );
  43. min = Math.min( uA, uB );
  44. output = (( viaID ) ? document.getElementById("odd") : document.all.odd );
  45.  
  46. output.innerHTML = "<p>The odd number's between " + (Math.min( uA, uB)) + " and " + (Math.max( uA, uB)) + " are:</p><hr />";
  47. for ( var x = min; x <= oLen; x++ ) {
  48. odds[x] = x / 2 ;
  49. OdN = parseFloat( odds[x].toString().split(/(^\d+$)/)[0] );
  50. output.innerHTML += (( odds[(OdN * 2)] === undefined ) ? "" : "<b>" + ( OdN * 2 ) + "</b>, " )
  51. } output.innerHTML += "<hr />";
  52. };
  53. // ]]>
  54. </script>
  55. </head>
  56. <body>
  57. <div id="main">
  58. <table frame="box" rules="none" summary="Getting Odd number&apos;s between two integer">
  59. <caption><span>JavaScript DEMO:</span> Getting the Odd Number's Between A &amp; B</caption>
  60. <colgroup align="center">
  61. <col />
  62. <col />
  63. <col />
  64. </colgroup>
  65. <thead>
  66. <tr>
  67. <th><label for="unitA">Unit A</label></th>
  68. <th><label for="unitB">Unit B</label></th>
  69. <th><button id="btn" name="btn" onclick="result();">Show The Odd's!</button></th>
  70. </tr>
  71. </thead>
  72. <tfoot>
  73. <tr>
  74. <th>Result&apos;s</th>
  75. <td colspan="2"><div id="odd" style="text-align: left;"></div></td>
  76. </tr>
  77. </tfoot>
  78. <tbody>
  79. <tr>
  80. <td><input type="text" id="unitA" name="unitA" value="" size="10" /></td>
  81. <td><input type="hidden" id="base" name="base" value="" /><input type="text" id="unitB" name="unitB" value="" size="10" /></td>
  82. <td style="background-color : #ccc;"> </td>
  83. </tr>
  84. </tbody>
  85. </table>
  86. </div>
  87. </body>
  88. </html>
Last edited by essential; May 6th, 2009 at 12:21 am. Reason: Typo
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Write a JavaScript/HTML program that inputs two integers a and b

 
0
  #6
May 6th, 2009
There's been some changes in my first posted code, and you will need to replace the whole <script></script> block, to this one.
I've removed all unnecessary line's in the code:
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. var result, odds, viaID, oLen, min;
  4. viaID = Boolean( document.getElementBy );
  5. odds = [];
  6. result = function() {
  7. uA = parseInt((( viaID ) ? document.getElementById("unitA").value : document.all.unitA.value ));
  8.  
  9. uB = parseInt((( viaID ) ? document.getElementById("unitB").value : document.all.unitB.value ));
  10.  
  11. oLen = Math.max( uA, uB );
  12. min = Math.min( uA, uB );
  13. output = (( viaID ) ? document.getElementById("odd") : document.all.odd );
  14.  
  15. output.innerHTML = "<p>The odd number's between " + min + " and " + oLen + " are:</p><hr />";
  16. for ( var x = min; x <= oLen; x++ ) {
  17. odds[x] = x / 2 ;
  18. OdN = parseFloat( odds[x].toString().split(/(^\d+$)/)[0] );
  19. output.innerHTML += (( odds[(OdN * 2)] === undefined ) ? "" : "<b>" + ( OdN * 2 ) + "</b>, " )
  20. } output.innerHTML += "<hr />";
  21. };
  22. // ]]>
  23. </script>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC