| | |
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
![]() |
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...
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
So find a JavaScript forum.
Java != JavaScript
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
----------------------------------------------
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
Try this:
javascript Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>JavaScript DEMO : Odd Numbers</title> <style type="text/css"> /* <![CDATA[ */ table { border : 1px solid #D0D0D0; border-collapse : collapse; text-align : left; width : 70%; } td, th { border-bottom : 1px solid #D0D0D0; padding : .300em; } input[type='text'] { border-bottom : 2px solid #D0D0D0; color : #696969; font-weight : bold; height : 17px; text-align : center; } /* ]]> */ </style> <script type="text/javascript"> // <![CDATA[ var result, odds, viaID; viaID = Boolean( document.getElementBy ); odds = []; result = function() { uA = parseInt((( viaID ) ? document.getElementById("unitA").value : document.all.unitA.value )); uB = parseInt((( viaID ) ? document.getElementById("unitB").value : document.all.unitB.value )); oLen = Math.max( uA, uB ); min = Math.min( uA, uB ); output = (( viaID ) ? document.getElementById("odd") : document.all.odd ); output.innerHTML = "<p>The odd number's between " + (Math.min( uA, uB)) + " and " + (Math.max( uA, uB)) + " are:</p><hr />"; for ( var x = min; x <= oLen; x++ ) { odds[x] = x / 2 ; OdN = parseFloat( odds[x].toString().split(/(^\d+$)/)[0] ); output.innerHTML += (( odds[(OdN * 2)] === undefined ) ? "" : "<b>" + ( OdN * 2 ) + "</b>, " ) } output.innerHTML += "<hr />"; }; // ]]> </script> </head> <body> <div id="main"> <table frame="box" rules="none" summary="Getting Odd number's between two integer"> <caption><span>JavaScript DEMO:</span> Getting the Odd Number's Between A & B</caption> <colgroup align="center"> <col /> <col /> <col /> </colgroup> <thead> <tr> <th><label for="unitA">Unit A</label></th> <th><label for="unitB">Unit B</label></th> <th><button id="btn" name="btn" onclick="result();">Show The Odd's!</button></th> </tr> </thead> <tfoot> <tr> <th>Result's</th> <td colspan="2"><div id="odd" style="text-align: left;"></div></td> </tr> </tfoot> <tbody> <tr> <td><input type="text" id="unitA" name="unitA" value="" size="10" /></td> <td><input type="hidden" id="base" name="base" value="" /><input type="text" id="unitB" name="unitB" value="" size="10" /></td> <td style="background-color : #ccc;"> </td> </tr> </tbody> </table> </div> </body> </html>
Last edited by essential; May 6th, 2009 at 12:21 am. Reason: Typo
There's been some changes in my first posted code, and you will need to replace the whole
I've removed all unnecessary line's in the code:
<script></script> block, to this one. I've removed all unnecessary line's in the code:
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> // <![CDATA[ var result, odds, viaID, oLen, min; viaID = Boolean( document.getElementBy ); odds = []; result = function() { uA = parseInt((( viaID ) ? document.getElementById("unitA").value : document.all.unitA.value )); uB = parseInt((( viaID ) ? document.getElementById("unitB").value : document.all.unitB.value )); oLen = Math.max( uA, uB ); min = Math.min( uA, uB ); output = (( viaID ) ? document.getElementById("odd") : document.all.odd ); output.innerHTML = "<p>The odd number's between " + min + " and " + oLen + " are:</p><hr />"; for ( var x = min; x <= oLen; x++ ) { odds[x] = x / 2 ; OdN = parseFloat( odds[x].toString().split(/(^\d+$)/)[0] ); output.innerHTML += (( odds[(OdN * 2)] === undefined ) ? "" : "<b>" + ( OdN * 2 ) + "</b>, " ) } output.innerHTML += "<hr />"; }; // ]]> </script>
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Invalid character error from Dynamic Drive code
- Next Thread: insert row on event
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n






