![]() |
Help Creating Unit Converter
Hi all --
I realize this is probably pretty simple, but it's been a while since I did any Javascripting, and things have changed a great deal. My apologies if I sound a bit clueless. I need to create a conversion tool. On one side of the tool are 4 form boxes. On the other, just text (not in form boxes). Under the covers, I have formulas for converting the numbers -- mostly basic math functions. So, the user types in numbers, clicks convert and the text changes. For some reason, I'm having a hard time getting this to go. How can I get the results of these calculations to show up as text within a DIV tag and not inside a form element? There are lots of examples of getting these calculations to appear within form boxes, but not within DIVs. Any examples would be greatly appreciated. This page is already using the Dojo toolkit for some other functionality, is this something I could leverage here to build my Javascript? Thanks in advance for your patience. |
I don't know squat about dojo, but all you need to do to populate a div (or a lot of other elements) is use the .innerHTML assignment. So, in the most general of terms use...
Code:
myDiv.innerHTML=conversion_result;Code:
myInput.value=conversion_result; |
You can write to element.innerHTML or add or replace a text node-
element.innerHTML=txt; parentof_original_node.replace(document.createTextNode(txt), original_node) |
So, I've got form boxes named a, b, c, d.
I've got DIV tags named x1, x2, x3, x4, x5, x6, x7. Here's my code... any idea why the script isn't inserting the text into my DIV tags? Code:
function convert(form) { |
I don't see anything wrong in the code you posted apart from eval(), so the problem seems to lie elsewhere. This test-rig works for me but of course I have no idea what values ought to be entered in the four textboxes.
Code:
<form name= "myform">Why should I do anything for posterity? What has posterity ever done for me? - Groucho Marx (1890 - 1977) |
I think I've got it working now... not sure what was going on, but it seems to be working OK.
Thanks everyone! |
| All times are GMT +1. The time now is 02:10 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.