Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Trying to make automotive physics calc

    Trying to make automotive physics calc will need help..

    I can't get the inputbox14 to work...



    <html>
    <head>

    <script>
    function writetext (form) {
    //inputfeilds
    var TotalCarWeight = form.inputbox.value;

    var FrontWeightDistribution = form.inputbox2.value;
    //Cal
    var RearWeightDistribution = 100-FrontWeightDistribution;
    form.inputbox3.value = 100-FrontWeightDistribution;
    //Input3
    var FrontShockStrokeHeight = form.inputbox4.value;

    var RearShockStrokeHeight = form.inputbox5.value;

    var FrontRideHeight = form.inputbox6.value;

    var RearRideHeight = form.inputbox7.value;

    var FrontMotionRatio = 1;
    form.inputbox8.value = 1;

    var RearMotionRatio = 1;
    form.inputbox9.value = 1;

    var TotalFrontWeight = (TotalCarWeight*FrontWeightDistribution)/100;
    form.inputbox10.value = (TotalCarWeight*FrontWeightDistribution)/100;
    //Input4

    var SplitFrontCornerWeight = TotalFrontWeight/2;
    form.inputbox11.value = TotalFrontWeight/2;
    //Input 5
    var Frontcornerstaticload = (SplitFrontCornerWeight/FrontMotionRatio);
    form.inputbox12.value = (SplitFrontCornerWeight/FrontMotionRatio);

    var FrontCornerSpringRate = (Frontcornerstaticload/FrontShockStrokeHeight);
    form.inputbox13.value = (Frontcornerstaticload/FrontShockStrokeHeight);

    var FrontCornerWheelRate = (FrontCornerSpringRate)*pow(FrontCornerSpringRate,1);
    form.inputbox14.value = (FrontCornerSpringRate)*pow(FrontCornerSpringRate,1);


    var TotalRearWeight = (TotalCarWeight*RearWeightDistribution)/100;
    form.inputbox15.value = (TotalCarWeight*RearWeightDistribution)/100;

    var SplitRrearCornerWeight = TotalRearWeight/2;
    form.inputbox16.value = TotalRearWeight/2;

    }
    </script>

    </head>
    <body>
    <div id="back">
    <h1> Tuning Guru </h1>

    <form name="carweight">
    <p id="problem"> Total Curb Weight:
    <input type="text" name="inputbox" Value="" >
    </p>
    <p id="problem"> FrontWeightDistribution:
    <input type="text" name="inputbox2
    " Value="">
    </p>
    <p> Rear Weight Distribution :
    <input type="text" name="inputbox3" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <form name="FrontShockStrokeHeight">
    <p id="problem"> Front Shock Stroke Height:
    <input type="text" name="inputbox4" Value="" >
    </p>
    <form name="RearShockStrokeHeight">
    <p id="problem"> Rear Shock Stroke Height:
    <input type="text" name="inputbox5" Value="" >
    </p>
    <form name="FrontRideHeight">
    <p id="problem"> Front Ride Height:
    <input type="text" name="inputbox6" Value="" >
    </p>
    <form name="RearRideHeight">
    <p id="problem"> Rear Ride Height:
    <input type="text" name="inputbox7" Value="" >
    </p>
    <p> Front Motion Ratio:
    <input type="text" name="inputbox8" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Motion Ratio:
    <input type="text" name="inputbox9" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <div id="solved">
    <p> Total Front Weight:
    <input type="text" name="inputbox10" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Split Front Corner Weight:
    <input type="text" name="inputbox11" Value="(click for results)"onFocus="writetext(this.form)">
    </p>

    <p> Front Corner Static Load:
    <input type="text" name="inputbox12" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Front Corner Spring Rate:
    <input type="text" name="inputbox13" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Front Corner Wheel Rate:
    <input type="text" name="inputbox14" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Total Rear Weight:
    <input type="text" name="inputbox15" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Split Rear Corner Weight:
    <input type="text" name="inputbox16" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Static Load:
    <input type="text" name="inputbox17" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Spring Rate:
    <input type="text" name="inputbox18" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Wheel Rate:
    <input type="text" name="inputbox20" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    </div>
    </form>
    </div>
    </body>
    </html>


  • #2
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    newer code


    <html>
    <head>

    <script>
    function writetext (form) {
    //inputfeilds
    var TotalCarWeight = form.inputbox.value;

    var FrontWeightDistribution = form.inputbox2.value;
    //Cal
    var RearWeightDistribution = 100-FrontWeightDistribution;
    form.inputbox3.value = 100-FrontWeightDistribution;
    //Input3
    var FrontShockStrokeHeight = form.inputbox4.value;

    var RearShockStrokeHeight = form.inputbox5.value;

    var FrontRideHeight = form.inputbox6.value;

    var RearRideHeight = form.inputbox7.value;

    var FrontMotionRatio = 1;
    form.inputbox8.value = 1;

    var RearMotionRatio = 1;
    form.inputbox9.value = 1;

    var TotalFrontWeight = (TotalCarWeight*FrontWeightDistribution)/100;
    form.inputbox10.value = (TotalCarWeight*FrontWeightDistribution)/100;
    //Input4

    var SplitFrontCornerWeight = TotalFrontWeight/2;
    form.inputbox11.value = TotalFrontWeight/2;
    //Input 5
    var Frontcornerstaticload = (SplitFrontCornerWeight/FrontMotionRatio);
    form.inputbox12.value = (SplitFrontCornerWeight/FrontMotionRatio);

    var FrontCornerSpringRate = (Frontcornerstaticload/FrontShockStrokeHeight);
    form.inputbox13.value = (Frontcornerstaticload/FrontShockStrokeHeight);

    var FrontCornerWheelRate = (FrontCornerSpringRate)*pow(FrontMotionRatio,1);
    form.inputbox14.value = (FrontCornerSpringRate)*pow(FrontMotionRatio,1);


    var TotalRearWeight = (TotalCarWeight*RearWeightDistribution)/100;
    form.inputbox15.value = (TotalCarWeight*RearWeightDistribution)/100;

    var SplitRrearCornerWeight = TotalRearWeight/2;
    form.inputbox16.value = TotalRearWeight/2;

    }
    </script>

    </head>
    <body>
    <div id="back">
    <h1> Tuning Guru </h1>

    <form name="carweight">
    <p id="problem"> Total Curb Weight:
    <input type="text" name="inputbox" Value="" >
    </p>
    <p id="problem"> FrontWeightDistribution:
    <input type="text" name="inputbox2
    " Value="">
    </p>
    <p> Rear Weight Distribution :
    <input type="text" name="inputbox3" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <form name="FrontShockStrokeHeight">
    <p id="problem"> Front Shock Stroke Height:
    <input type="text" name="inputbox4" Value="" >
    </p>
    <form name="RearShockStrokeHeight">
    <p id="problem"> Rear Shock Stroke Height:
    <input type="text" name="inputbox5" Value="" >
    </p>
    <form name="FrontRideHeight">
    <p id="problem"> Front Ride Height:
    <input type="text" name="inputbox6" Value="" >
    </p>
    <form name="RearRideHeight">
    <p id="problem"> Rear Ride Height:
    <input type="text" name="inputbox7" Value="" >
    </p>
    <p> Front Motion Ratio:
    <input type="text" name="inputbox8" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Motion Ratio:
    <input type="text" name="inputbox9" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <div id="solved">
    <p> Total Front Weight:
    <input type="text" name="inputbox10" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Split Front Corner Weight:
    <input type="text" name="inputbox11" Value="(click for results)"onFocus="writetext(this.form)">
    </p>

    <p> Front Corner Static Load:
    <input type="text" name="inputbox12" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Front Corner Spring Rate:
    <input type="text" name="inputbox13" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Front Corner Wheel Rate:
    <input type="text" name="inputbox14" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Total Rear Weight:
    <input type="text" name="inputbox15" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Split Rear Corner Weight:
    <input type="text" name="inputbox16" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Static Load:
    <input type="text" name="inputbox17" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Spring Rate:
    <input type="text" name="inputbox18" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    <p> Rear Corner Wheel Rate:
    <input type="text" name="inputbox20" Value="(click for results)"onFocus="writetext(this.form)">
    </p>
    </div>
    </form>
    </div>
    </body>
    </html>

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    There is no such thing as pow( ) built into JavaScript.

    You need to use Math.pow( )

    ***********

    Named <form> tags are obsolete. Us an ID instead.

    ***********

    You have multiple <p id="problem">. That is illegal HTML. Each id *must* be unique on a given page. If you meant to use this to drive your CSS, use a class, instead.

    ***********

    Why do you use silly names for you <form> fields like "inputbox" and "inputbox13", et al.?

    Why not use *MEANINGFUL* names.

    So (to start):
    Code:
    <form id="carweight">
    <p class="problem"> Total Curb Weight: <input name="totCurbWeight" Value="" ></p>
    <p class="problem"> FrontWeightDistribution: <input name="frontDistPct" Value="">%</p>
    <p> 
        Rear Weight Distribution : 
        <input name="rearDistPct" Value="(click for results)" onFocus="writetext(this.form)">%
    </p>
    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:

    dannothemanno (05-18-2013)

  • #4
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    can anyone help me via video chat on googlehangout? thanks..

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You also have nested <form> tags, which are also illegal.

    Luckily for you, all your <form> tags but the first one are being ignored.
    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:

    dannothemanno (05-18-2013)

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Here...cleaned up version of your code. You had a lot of inconsistencies in the names. Upper vs. lower case.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Tuning Guru</title>
    <style type="text/css">
    input {
        background-color: #eeeeee;
    }
    input.data {
        background-color: white;
    }
    </style>
    </head>
    <body>
    <div id="back">
    <h1> Tuning Guru </h1>
    
    <form id="car">
    <p class="problem"> Total Curb Weight: <input class="data" name="totCurbWeight"  ></p>
    <p class="problem"> FrontWeightDistribution: <input class="data" name="fDistPct" />%</p>
    <p> Rear Weight Distribution : <input name="rDistPct" readonly="readonly" />%</p>
    <p class="problem"> Front Shock Stroke Height: <input  class="data" name="fShockHt"/></p>
    <p class="problem"> Rear Shock Stroke Height:<input  class="data" name="rShockHt" /></p>
    <p class="problem"> Front Ride Height: <input  class="data" name="fRideHt"/></p>
    <p class="problem"> Rear Ride Height: <input class="data" name="rRideHt"  /></p>
    <p> Front Motion Ratio: <input name="fMotionRatio" readonly="readonly" /></p>
    <p> Rear Motion Ratio: <input name="rMotionRatio" readonly="readonly" /></p>
    <div id="solved">
        <p> Total Front Weight: <input name="fTotalWt" readonly="readonly" /></p>
        <p> Split Front Corner Weight: <input name="fSplitWt" readonly="readonly" /></p>
        <p> Front Corner Static Load: <input name="fStaticLoad" readonly="readonly" /></p>
        <p> Front Corner Spring Rate: <input name="fSpringRate" readonly="readonly" /></p>
        <p> Front Corner Wheel Rate: <input name="fWheelRate" readonly="readonly" /></p>
        <p> Total Rear Weight: <input name="rTotalWt" readonly="readonly" /></p>
        <p> Split Rear Corner Weight: <input name="rSplitWt" readonly="readonly" /></p>
        <p> Read Corner Static Load: <input name="rStaticLoad" readonly="readonly" /></p>
        <p> Read Corner Spring Rate: <input name="rSpringRate" readonly="readonly" /></p>
        <p> Read Corner Wheel Rate: <input name="rWheelRate" readonly="readonly" /></p>
    </div>
    </form>
    </div>
    
    <script type="text/javascript">
    var form = document.getElementById("car");
    var inps = form.getElementsByTagName("input");
    for ( var i = 0; i < inps.length; ++i )
    {
        inp = inps[i];
        if ( inp.className == "data" )
        {
           inp.onchange = datacheck;
        }
    }
    
    function datacheck( )
    {
        if ( this.name == "fDistPct" )
        {
            form.rDistPct.value = 100.0 - this.value;
        }
        for ( var i = 0; i < inps.length; ++i )
        {
            var inp = inps[i];
            if ( inp.className == "data" )
            {
                var val = inps[i].value.replace(/\s/g,"");
                if ( val == "" || isNaN(val) ) { return; /* form incomplete */ }
            }
        }
        // all non-readonly form fields filled in...do the calculations
        var TotalCarWeight = Number(form.totCurbWeight.value);
        var FrontWeightDistribution = Number(form.fDistPct.value);
        var RearWeightDistribution = Number(form.rDistPct.value);
        var FrontShockStrokeHeight = Number(form.fShockHt.value);
        var RearShockStrokeHeight = Number(form.rShockHt.value);
        var FrontRideHeight = Number(form.fRideHt.value);
        var RearRideHeight = Number(form.rRideHt.value);
    
        var FrontMotionRatio = 1;
        form.fMotionRatio.value = FrontMotionRatio;
        var RearMotionRatio = 1;
        form.rMotionRatio.value = RearMotionRatio;
    
        var TotalFrontWeight = (TotalCarWeight*FrontWeightDistribution)/100;
        form.fTotalWt.value = TotalFrontWeight.toFixed(2);
    
        var SplitFrontCornerWeight = TotalFrontWeight/2;
        form.fSplitWt.value = SplitFrontCornerWeight.toFixed(2);
        var FrontCornerStaticLoad = (SplitFrontCornerWeight/FrontMotionRatio);
        form.fStaticLoad.value = FrontCornerStaticLoad.toFixed(2);
        var FrontCornerSpringRate = (FrontCornerStaticLoad/FrontShockStrokeHeight);
        form.fSpringRate.value = FrontCornerSpringRate.toFixed(2);
        var FrontCornerWheelRate = (FrontCornerSpringRate)*Math.pow(FrontMotionRatio,1);
        form.fWheelRate.value = FrontCornerWheelRate.toFixed(2);
    
        var TotalRearWeight = (TotalCarWeight*RearWeightDistribution)/100;
        form.rTotalWt.value = TotalRearWeight.toFixed(2);
    
        var SplitRearCornerWeight = TotalRearWeight/2;
        form.rSplitWt.value = SplitRearCornerWeight.toFixed(2);
        var RearCornerStaticLoad = (SplitRearCornerWeight/RearMotionRatio);
        form.rStaticLoad.value = RearCornerStaticLoad.toFixed(2);
        var RearCornerSpringRate = (RearCornerStaticLoad/RearShockStrokeHeight);
        form.rSpringRate.value = RearCornerSpringRate.toFixed(2);
        var RearCornerWheelRate = (RearCornerSpringRate)*Math.pow(RearMotionRatio,1);
        form.rWheelRate.value = RearCornerWheelRate.toFixed(2);
    }
    </script>
    </body>
    </html>
    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:

    dannothemanno (05-18-2013)

  • #7
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks... Thats a whole lot better then mine....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •