Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com temperature conversion

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 11-20-2012, 03:44 AM PM User | #1 shouts New to the CF scene   Join Date: Nov 2012 Posts: 2 Thanks: 1 Thanked 0 Times in 0 Posts temperature conversion Having trouble with this code... trying to change status of textboxes with onclick event of radio button - any tips? Code: ``` Convert Temperature

Convert Temperature

From Fahrenheit to Celsius
From Celsius to Fahrenheit

Degrees Fahrenheit:
Degrees Celsius:

```
11-20-2012, 05:39 AM   PM User | #2
Logic Ali
Senior Coder

Join Date: Sep 2010
Location: London
Posts: 1,027
Thanks: 0
Thanked 206 Times in 201 Posts
Quote:
 Originally Posted by shouts Having trouble with this code... trying to change status of textboxes with onclick event of radio button - any tips?
Tips
1. USE THE ERROR CONSOLE.
2. Lay-out your code so that all brace pairs are vertically aligned (never mind the listings you've seen that don't); that way any orphaned braces are easy for you and others to spot.
3. USE THE ERROR CONSOLE.

 11-20-2012, 07:28 AM PM User | #3 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,962 Thanks: 75 Thanked 4,309 Times in 4,276 Posts And here's a message I just posted on how to find/use the error console: http://www.codingforums.com/showpost...32&postcount=5 And by "vertically aligned", LogicAli means stuff like this: Code: ``` function Convert() { if (\$("rbCelsius").checked) { F = \$("txtCelsius").value * 9 / 5 + 32; \$("Fahrenheit").value = Math.round(F); } else if (\$("rbFahrenheit").checked) { C = \$("txtFahrenheit").value -32) * 5 / 9; \$("Celsius").value = Math.round(C); }``` And OH! Look at that! Where's the } to match the very first { there?? __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
 Users who have thanked Old Pedant for this post: shouts (11-20-2012)
 11-20-2012, 02:48 PM PM User | #4 shouts New to the CF scene   Join Date: Nov 2012 Posts: 2 Thanks: 1 Thanked 0 Times in 0 Posts Thank you for your help! Fixed the bracket, used the debugger. Can it show the values for variables? (I'm a mainframe programmer, so I'm used to xped!) I'm getting a null value error in this section. Code: ``` function Convert() { if (\$("rbFahrenheit").checked) { F = parseFloat(("txtCelsius").value * 9 / 5 + 32); \$("Fahrenheit").value = Math.round(F); } else if (\$("rbCelsius").checked){ C = parseFloat((\$("txtFahrenheit").value -32) * 5 / 9); \$("Celsius").value = Math.round(C); } }```
11-20-2012, 03:16 PM   PM User | #5
Dormilich
Senior Coder

Join Date: Jan 2010
Location: Behind the Wall
Posts: 3,087
Thanks: 11
Thanked 327 Times in 323 Posts
afaik, the jQuery object does not have a checked property. you’d probably need to use the property getter. `\$("rbFahrenheit").prop("checked")`. maybe the `:checked` selector is also useful `if (\$("rbFahrenheit:checked"))`.
__________________
Quote:
 The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
André Behrens, NY Times Software Developer

 11-20-2012, 04:40 PM PM User | #6 AndrewGSW Senior Coder   Join Date: Apr 2011 Location: London, England Posts: 2,120 Thanks: 15 Thanked 354 Times in 353 Posts rbFahrenheit is the id so it needs to be preceded by '#' in the jQuery selector Code: `if (\$('#rbFahrenheit').is(':checked')) {` is() is another way to do this. I think we can even do this.. Code: `if (\$('#rbFahrenheit')[0].checked) {` .. but why would we? __________________ "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene. Validate your HTML and CSS Last edited by AndrewGSW; 11-20-2012 at 04:46 PM..
11-21-2012, 12:17 AM   PM User | #7
Logic Ali
Senior Coder

Join Date: Sep 2010
Location: London
Posts: 1,027
Thanks: 0
Thanked 206 Times in 201 Posts
Quote:
 Originally Posted by Dormilich afaik, the jQuery object does not have a checked property.
AFAICT jQuery isn't being used, just a half-baked aliasing function that I would re-write as:

Code:
```var \$ = function (id)
{
var elem = document.getElementById(id);

return ( elem && elem.id === id ? elem : null );
}```

 11-21-2012, 12:28 AM PM User | #8 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,962 Thanks: 75 Thanked 4,309 Times in 4,276 Posts LogicAli is of course correct. Look in the originally posted code: Code: ``` var \$ = function (id) { return document.getElementById(id); }``` So Code: `if (\$("rbFahrenheit").checked)` (et al.) *IS* correct. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
 11-21-2012, 01:39 AM PM User | #9 AndrewGSW Senior Coder   Join Date: Apr 2011 Location: London, England Posts: 2,120 Thanks: 15 Thanked 354 Times in 353 Posts Code: ``` var \$ = function (id) { return document.getElementById(id); }``` Oops, I missed that! __________________ "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene. Validate your HTML and CSS
 11-21-2012, 01:49 AM PM User | #10 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,962 Thanks: 75 Thanked 4,309 Times in 4,276 Posts I almost didn't answer the original post because I assumed it was using jQuery and I don't use jQuery so tend to avoid posts involving it. Then I noticed his home-built function and decided to stick by big foot in it. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
11-21-2012, 02:06 AM   PM User | #11
Old Pedant
Supreme Master coder!

Join Date: Feb 2009
Posts: 24,962
Thanks: 75
Thanked 4,309 Times in 4,276 Posts
Quote:
 Originally Posted by shouts Thank you for your help! Fixed the bracket, used the debugger. Can it show the values for variables?
Absolutely!

Are you using Chrome? (Below will be roughly the same in all browsers, but will be correct for Chrome.)

First, set a breakpoint in the code.
-- Click on the Sources tab
-- If the JS code is not shown, look for the little right arrow at the very top left
of the tab space and click on it. That will show you a list of the files being used for this page. Find the one with the JS code you are interested in and clock on it.
-- Find the line where you want to inspect values, etc., and click to the far left of it
-- A blue arrow will appear indicating you have a breakpoint on that line

Second, make sure you hit the breakpoint.
-- Hit a button, make a selection, click a link, etc., etc., Whatever you need to do to get your JS code to reach that breakpoint.
-- If the breakpoint will only be hit during page startup, just hit F5 to refresh the page

Third, look for your variable. Two ways:
(1) In the far right column, look for "Scope variables" and then for the KIND of variable: Local, Closure, Global. Expand the appropriate scope and find your variable. It will be there by name, with its value. (If it's an array, you can expand the array to find the individual elements. If it's an object, you can find the elements of the object.)
(2) [Often the easier choice!] Simply hover your mouse over any usage of the variable in the code visible in the Source tab. The value should pop up in a nice readable overlay.

*********

And all the above is just getting started with the debugger. There's a lot more you can do with it.

Look at "Watch Expressions". Investigate the little plus sign that is part of them.

Look at the little icons above "Watch Expressions". Hover over each one to find out what it is used for.

And more.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:17 AM.