Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do scripts work on one page only???? 1

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi all,

Tearing my hair out here. I'm just learning javascript on the fly here and spent half a day working in a simple calculation script where if a user clicks on a radio button and places a number in a textbox, the result appears in a "sub total" field. Here is the code on the page that works:
Code:
function addthem() {
    //FIRST INPUT VALUE
    var add1 = document.addem.input1.value
    var add1 = parseFloat(add1, 10)
    add1 = (isNaN(add1))?0:add1;

    //SECOND INPUT VALUE
    var add2 = document.addem.input2.value
    var add2 = parseFloat(add2, 10)
    add2 = (isNaN(add2))?0:add2;
    
    //ADD THEM TOGETHER
    return eval(add1) * eval(add2);
}

function addition() { 
document.addem.answer.value = addthem()
totalval(addem)
}
"input1" is the radio button with a value of 15
the "input2" is the text box that has an "onChange" event happening that will provide the answer in the "answer" field.
I got this code from this forums FAQ page
This page is located HERE

Great you say? well here is the cruncher. I have the exact same code on THIS PAGE
Look at the Creche section and the radio button for 'session 3' is supposed to multiply with the qty field next to it and provide the answer in the field on the right.

Why is it working on the first page and not this one? [mad]

Here is the code for the page that DOES NOT work. Any workable solution would get you a star!
Been working on this for too long!

Code:
function CrecheSess3() {
    //FIRST INPUT VALUE
    var add1 = document.addem.CrSess3.value
    var add1 = parseFloat(add1, 10)
    add1 = (isNaN(add1))?0:add1;

    //SECOND INPUT VALUE
    var add2 = document.addem.Sess3Qty.value
    var add2 = parseFloat(add2, 10)
    add2 = (isNaN(add2))?0:add2;
    
    //ADD THEM TOGETHER
    return eval(add1) * eval(add2);
}
function CrecheSess3Sub(){ document.addem.Sub3.value = "$" + CrecheSes3()}

Again, "CrSess3" is the radio button with a value of 3, "Sess3Qty" is the text field that is multiplied with the radio button and the answer is supposed to go into "Sub3"


-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Hi

Hmm... It think the two red function names should match.
Code:
function [red]CrecheSe[u]s[b]s[/b][/u]3()[/red] {
[/small]    //FIRST INPUT VALUE
    var add1 = document.addem.CrSess3.value
    var add1 = parseFloat(add1, 10)
    add1 = (isNaN(add1))?0:add1;

    //SECOND INPUT VALUE
    var add2 = document.addem.Sess3Qty.value
    var add2 = parseFloat(add2, 10)
    add2 = (isNaN(add2))?0:add2;
    
    //ADD THEM TOGETHER[/small]
    return add1 * add2;
}
function CrecheSess3Sub(){ document.addem.Sub3.value = "$" + [red]CrecheSe[u]s[/u]3()[/red]}
And remove those [tt]eval()[/tt] calls around the add1 and add2 values in the expression.

Feherke.
 
Feherke,

Doh!

Thanks. This line is working. Hopefully now, I'll be able to finish this form, bearing in mind that I still need to ad up the sub totals.

AS promised, a star to you. Thank you for your help

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top