473,606 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About document.getEle mentById() - Simple question for you pros in here!

4 New Member
I'm new to javascript, so I figure som of you guys in here can answer my question pretty easily:

I have this code which works:
[HTML]<script type="text/javascript">

</script>

</head>

<body>

<table>
<tr>
<th style="text-align: center;"> Adresse </th>
<th style="text-align: center;"> Salgspris </th>
<th style="text-align: center;"> Beboelsesareal </th>
</tr>
<tr>
<td> Klostergade 2 3. sal - 8000 Aarhus C </td>
<td> 2.495.000 kr </td>
<td> 119 kvadratmeter </td>
</tr>
<tr>
<td> Volden 12 3. sal - 8000 Aarhus C </td>
<td> 2.698.000 kr </td>
<td> 97 kvadratmeter </td>
</tr>
<tr>
<td> Vester Alle 27 2. sal tv - 8000 Aarhus C </td>
<td> 2.795.000 kr </td>
<td> 92 kvadratmeter </td>
</tr>
</table>

<form action="#" name="udregn">

<p> Indtast prisen <input id="pris" type="text" name="pris"> </p>
<p> Indtast areal <input id="areal" type="text" name="areal"> </p>
<p> <input id="meterpris" type="text" name="meterpris " disabled> kr pr. kvadratmeter </p>
<p> <input id="udregn" type="button" value="Beregn kvadratmeterpri sen"
onClick="docume nt.udregn.meter pris.value = document.udregn .pris.value / document.udregn .areal.value"> </p>

</form>
</body>
</html>
[/HTML]
But I want to separate my javascript from my html and I tried som different things like this:

[html]<script type="text/javascript">

window.onload = function ()
{
document.getEle mentById("udreg n").onClick =
function()
{

document.getEle mentById("pris" ).value / document.getEle mentById("areal ").value
}
}

</script>

</head>

<body>

<table>
<tr>
<th style="text-align: center;"> Adresse </th>
<th style="text-align: center;"> Salgspris </th>
<th style="text-align: center;"> Beboelsesareal </th>
</tr>
<tr>
<td> Klostergade 2 3. sal - 8000 Aarhus C </td>
<td> 2.495.000 kr </td>
<td> 119 kvadratmeter </td>
</tr>
<tr>
<td> Volden 12 3. sal - 8000 Aarhus C </td>
<td> 2.698.000 kr </td>
<td> 97 kvadratmeter </td>
</tr>
<tr>
<td> Vester Alle 27 2. sal tv - 8000 Aarhus C </td>
<td> 2.795.000 kr </td>
<td> 92 kvadratmeter </td>
</tr>
</table>

<form action="#" name="udregn">
<p> Indtast prisen <input id="pris" type="text" name="pris"> </p>
<p> Indtast areal <input id="areal" type="text" name="areal"> </p>
<p> <input id="meterpris" type="text" name="meterpris " disabled> kr pr. kvadratmeter </p>
<p> <input id="udregn" type="button" value="Beregn kvadratmeterpri sen"> </p>
</form>
</body>
</html>[/html]

It doesnt seem to work though - can I get som help?
Feb 7 '08 #1
4 1440
gits
5,390 Recognized Expert Moderator Expert
hi ...

try the following:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("udregn").onclick = function() { 
  2.     document.getElementById("meterpris").value = 
  3.         document.getElementById("pris").value 
  4.         / document.getElementById("areal").value;
note: onclick, and the output to the correct field

kind regards
Feb 7 '08 #2
Bjorndal
4 New Member
I'm stille having problems getting any output to the "meterpris"-field.

Any other suggestions?
Feb 8 '08 #3
gits
5,390 Recognized Expert Moderator Expert
I'm stille having problems getting any output to the "meterpris"-field.

Any other suggestions?
post the code you actually use ... the shown code worked so there has to be another error ...

using this:

Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     document.getElementById("udregn").onclick = function() { 
  3.         document.getElementById("meterpris").value = 
  4.             document.getElementById("pris").value 
  5.             / document.getElementById("areal").value;
  6.     }
  7. }
  8.  
should work :)

kind regards
Feb 8 '08 #4
Bjorndal
4 New Member
It does work :-) Thank you for your help!

regards
Feb 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8274
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
12
3890
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with both single quotes and no single quotes, but it doesn't work either way. What am I doing wrong? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById('weblogs').style.visibility='hidden';
4
5461
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
5
3093
by: Digital Puer | last post by:
I have the following HTML form: - radio button A (default selected) - radio button B - input field, of type "file" with "Choose" button - submit button I would like to have it so that if the user clicks on the "Choose" button of the input field (to select a file on the local disk), then radio button B is automatically
10
2243
by: sp | last post by:
I create an xml file in a text editor: <?xml version="1.0" encoding="utf-8"?> <elts> <elt id="1" class="c1">content1</elt> <elt id="2" class="c1">content2</elt> </elts> Then I load the file via xmlHttpRequest into xmlData variable. Why does xmlData.getElementById('1') return null and xmlData.firstChild.childNodes.className returns null also?
4
1582
by: Extremest | last post by:
I have noticed that one like mysql.com when you do a search it takes you to a page that says your search is running then it loads up the results on another page. How can I do this. I figured it would help for any query that might take more than a couple seconds to have time to run.
5
11126
by: garfy | last post by:
Hi i get this error in validation Line 22 column 6: document type does not allow element "title" here. <title>Seo Web Design Los Angeles - Web Design And Search Engine Optimization L But the title is inside the head so why I am getting this?
4
4567
by: Soren | last post by:
Hello, here is my short example ready to paste. Just one style script and some body. I just wanted to see the value of style.left, but why it isn't working. I am wondering a lot of time what is wrong but i failed so please be so kind and help me. ------------------------------------------------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">...
3
1970
by: Italio Novuas | last post by:
Hi all, let me begin by saying that I *ALMOST* have this complete! What I'm trying to do is make it so my text area shows the innerHTML of any select item with the same value. For example, if I have a select list with 5 options: <select name="select" onChange="changeValues();"> <option value="1">Option 1</option> <option value="1">More stuff on option 1</option> <option value="1">EVEN more option one stuff!!</option> <option...
0
7978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8448
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8126
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6796
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5470
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3948
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1572
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.