•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,326 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,967 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3141 | Replies: 3
![]() |
•
•
Join Date: Jan 2005
Location: defiance, oh
Posts: 19
Reputation:
Rep Power: 4
Solved Threads: 1
I have created the foloowing javascript and placed it in a file called common.js. it gets called on a onChange event. it works up till it gets to setting the value (i think). Being my first script i'm really at a loss why it errors out. I tried .value() = and .value( prevbal - demand..... TIA
function recalcnet(txt) {
switch (txt) {
case '0' :
recalcnet1();
break;}}
function recalcnet1() {
var prevbal = 0;
var demand = 0;
var whatif = 0;
var sched = 0;
prevbal = document.getElementById('BegInvTextbox').value;
demand = document.getElementById('dm1TextBox').value;
whatif = document.getElementById('ifm1TextBox').value;
sched = document.getElementById('fmm1TextBox').value;
document.getElementById('nm1TextBox').value(prevbal - demand + whatif + sched)}; Last edited by tgreer : Apr 11th, 2006 at 4:07 pm. Reason: Added the ever-missing [code] tags.
Here is little example to get you started on debugging. I would place some alerts in there to see what's going on. I am not exactly sure what you’re trying to do with the line below.
You already know the value of prevbal… etc. If you want to set the element below to the value of those numbers try something like I did below. I am guessing those var are numbers. But in your code they will be treated as strings.
You already know the value of prevbal… etc. If you want to set the element below to the value of those numbers try something like I did below. I am guessing those var are numbers. But in your code they will be treated as strings.
document.getElementById('nm1TextBox').value(prevbal - demand + whatif + sched)<html><head>
<title></title>
<script>
function testFn()
{
var test1 = document.getElementById('Num1').value;
if(test1 != "")
{
alert("Number 1: " + test1);
}
var test2 = document.getElementById('Num2').value;
if(test2 != "")
{
alert("Number 2: " + test2);
}
if (test1 != "" && test2 != "")
{
var test3 = document.getElementById('Total');
var total = test3.value = parseInt(test1) + parseInt(test2);
alert("Total Num 1 + Num2: " + total);
}
}
</script>
</head>
<body>
<label value"num1"> Number 1 </label> <input size="2" id="Num1" onChange="testFn()">
<label value"num2"> + Number 2 </label> <input size="2" id="Num2" onChange="testFn()">
<label value="fullName"> Total: </label> <input size="4" id="Total" type=text>
</body>
</html> ![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- why dont it work? (JavaScript / DHTML / AJAX)
- how does this work? (JavaScript / DHTML / AJAX)
- how do i get this to work document.getElementById (Java)
- getElementById is not a function (HTML and CSS)
- Please help me make this script work in Netscape (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript in mozilla firefox
- Next Thread: Location of Javascript files on server



Linear Mode