开发者

Extracting about 10 variables from Javascript code(after running) and writing to page?

开发者 https://www.devze.com 2023-03-31 16:49 出处:网络
I finished my Javascript code and its about 3,000 lines long.There are many variables within the code(60+), but a few of the variables I\'d like to write to my page such as

I finished my Javascript code and its about 3,000 lines long. There are many variables within the code(60+), but a few of the variables I'd like to write to my page such as

totalTime
longitudinalAcceleration
shiftTime
numberOfShifts
corneringTime
numberOfCorners
instantaneousCoefficientOfFriction
totalFuel
meanLongAccel
meanHorsepower

These are all variables within the Jscript code(not included because it would be too long). What I'd like to be able to do is to write this code to my main HTML page which calls the function. THe javascript function is called images.js(dont ask lol). I'm pretty sure I need an output variable thats an object within the Jscript file. This part I'm not too sure about how to do, or how to later write parts of the object variable in the actual HTML page.

Basically I am running Main Calculation() which is contained within image.js, after this function is ran, I want to pull those variables and write them to my HTML page. Those are the variables you see above. How do I grab those variables after the calculation has been ran? I'm pretty sure I need to use jQuery or Javascript to write the variables to the page??

Here is a link to the page if it helps http://www.fsaesim.com/Products.html

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript" src="images.js"></script>
    <script type="text/javascript">
        function ShowCalculation() {
            Main($("#vehicleWeightTxt").val(), $("#tireChoiceSel").val(), $("#wheelBaseTxt").val(), $("#wheelRadiusTxt").val(), $("#trackWidthTxt").val(), $("#hcgTxt").val(), $("#weightDistributionTxt").val(), $("#shiftRpmTxt").val(), $("#ntTxt").val());


        }
    </script>

</head>

<body id="page4">
    <div class="body1">
    <div class="body2">
    <div class="body5">
        <div class="main">

            <header>
                <div class="wrapper">
                <h1><a href="index.html" id="logo">Progress Business Company</a></h1>
                <nav>
                    <ul id="menu">
                        <li id="nav1" class="active"><a href="index.html">Home<span>Page</span></a></li>

                        <li id="nav2"><a href="News.html">News<span>Updates</span></a></li>

                        <li id="nav3"><a href="Services.html">Available<span>Features</span></a></li>

                        <li id="nav4"><a href="Products.html">Run<span>Simulation</span></a></li>

                        <li id="nav5"><a href="Contacts.html">Contact<span>Support</span></a></li>
                    </ul>
                </nav>
                </div>
            </header>

        </div>
    </div>
    </div>
    </div>
    <div class="body1">
        <div class="main">
        <br />
        <table border="0">
        <tr>
        <td>
        Tire Choice
        </td>
        <td>
        <select id="tireChoiceSel">
        <option value="1">Michelin 13"</option>
        <option value="2">Hoosier 13" Large</option>
        <option value="3">Hoosier 13" Small</option>
        <option value="4">Mexican Tires</option>
        </select>
        </td>
        <td>
        Engine:
        </td>
        <td><select id="engineSelectionSel">
        <option value="1">Yamaha R6 - 4 Cylinder</option>
        <option value="2">Yamaha WR450 - 1 Cylinder</option>
        <option value="3">Honda CBR600RR - 4 Cylinder </option>
        <option value="4">Suzuki GSXR600 - 4 Cylinder</option>
        </select>
        </td>
        <td>
        Torque Curve:
        </td>
        <td>
        <select id="torqueCurveSel">
        <option value="1">Cornell Curve 2008</option>
        <option value="2">MIT Curve 2008</option>
        <option value="3">RMIT Curve 2008 </option>
        <option value="4">Fullerton Curve 2008</option>
        </select>
        </td>
        </tr>

        <tr>
        <td>
        Vehicle Weight:
        </td>
        <td>
        <input type="text" id="vehicleWeightTxt" value="530" size="3" />
        </td>
        <td>
        Number of NOS:
        </td>
        <td>
        <input type="text" id="Text1" value="100" size="3" />
        </td>
        <td>
        NOS Bottle #1:
        </td>
        <td>
        <input type="text" id="Text2" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Wheel Base:
        </td>
        <td>
        <input type="text" id="wheelBaseTxt" value="61" size="3" />
        </td>
        <td>
        NOS Bottle #2:
        </td>
        <td>
        <input type="text" id="Text3" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #3:
        </td>
        <td>
        <input type="text" id="Text4" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Wheel Radius:
        </td>
        <td>
        <input type="text" id="wheelRadiusTxt" value="10.25" size="3"  />
        </td>
        <td>
        NOS Bottle #4:
        </td>
        <td>
        <input type="text" id="Text5" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #5:
        </td>
        <td>
        <input type="text" id="Text6" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Track Width:
        </td>
        <td>
        <input type="text" id="trackWidthTxt" value="50" size="3" />
        </td>
        <td>
        NOS Bottle #6:
        </td>
        <td>
        <input type="text" id="Text7" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #7:
        </td>
        <td>
        <input type="text" id="Text8" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Center of Gravity: 
        </td>
        <td>
        <input type="text" id="hcgTxt" value="12" size="3" />
        </td>
        <td>
        NOS Bottle #8:
        </td>
        <td>
        <input type="text" id="Text9" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #9:
        </td>
        <td>
        <input type="text" id="Text10" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Weight Distribution: 
        </td>
        <td>
        <input type="text" id="weightDistributionTxt" value="0.50" size="3" />
        </td>
        <td>
        NOS Bottle #10:
        </td>
        <td>
        <input type="text" id="Text11" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #11:
        </td>
        <td>
        <input type="text" id="Text12" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Shift RPM: 
        </td>
        <td>
        <input type="text" id="shiftRpmTxt" value="9500" size="3" />
        </td>
        <td>
        NOS Bottle #12:
        </td>
        <td>
        <input type="text" id="Text13" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #13:
        </td>
        <td>
        <input type="text" id="Text14" value="3000" size="3" />
        </td>
        </tr>

        <tr>
        <td>
        Final Drive Ratio: 
        </td>
        <td>
        <input type="text" id="ntTxt" value="2.86" size="3" />
        </td>
        <td>
        NOS Bottle #14:
        </td>
        <td>
        <input type="text" id="Text15" value="3000" size="3" />
        </td>
        <td>
        NOS Bottle #15:
        </td>
        <td>
        <input type="text" id="Text16" value="3000" size="3" />
        </td>
        </tr>


















        </table>



    <center><input type="submit" value="Calculate" onclick="ShowCalculation(); return false;" /></center>
        </div>
    </div>
    <div class="body4">
        <div class="main">
            <article id="content2">
                <div class="wrapper">
                    <section class="col3">
                        <h4>Why Us?</h4>
                        <ul class="list1">

                            <li><a href="#">Professional Engineers</a></li>

                            <li><a href="#">Years of Experience</a></li>

                            <li><a href="#">Vehicle Dynamics Experts</a></li>
                        </ul>
                    </se开发者_如何学Goction>
                    <section class="col3 pad_left2">
                        <h4>Address</h4>
                        <ul class="address">
                            <li><span>Location:</span>United States, CA</li>

                            <li><span>City:</span>Northridge</li>

                            <li><span>Phone:</span>1-888-888-8888</li>

                            <li><span>Email:</span><a href="mailto:fsaesimulation@gmail.com">Contact Us</a></li>
                        </ul>
                    </section>
                    <section class="col3 pad_left2">
                        <h4>Follow Us</h4>
                        <ul id="icons">
                            <li><a href="#"><img src="images/icon1.jpg" alt="">Facebook</a></li>
                            <li><a href="#"><img src="images/icon2.jpg" alt="">Twitter</a></li>

                        </ul>
                    </section>
                    <section class="col2 right">
                        <h4>Search The Site</h4>
                        <form id="newsletter" method="post">
                            <div>
                                <div class="wrapper">
                                    <input class="input" type="text" value="Type Your Email Here"  onblur="if(this.value=='') this.value='Type Your Email Here'" onFocus="if(this.value =='Type Your Email Here' ) this.value=''" />
                                </div>
                                <a href="#" class="button" onClick="document.getElementById('newsletter').submit()">Search</a>
                            </div>
                        </form>
                    </section>
                </div>
            </article>
<!-- content end -->
        </div>
    </div>


if I get it right, you compute these values, they are a result you want to display,

I would suggest to create a div where you want to show them (like, under the calculate button)(or a modal box, that would replace the alert).

and in js, a bit basic but well:

var stuffToShow = [
'totalTime',
'longitudinalAcceleration',
'shiftTime',
'numberOfShifts',
'corneringTime',
'numberOfCorners',
'instantaneousCoefficientOfFriction',
'totalFuel',
'meanLongAccel',
'meanHorsepower'
];

var someHtml = '';
$(stuffToShow).each( function () {
    someHtml += '<div id="'+this+'">'+this+': '+youResultObject[this]+</div>;
});

$('#yourResultDiv').html(someHtml).slidedown('slow');


It is not completely clear what you are trying to do, but if this page is linked to from a javascript-based page that does the calculations, you can pass the variables using GET or POST (see here: http://www.php.net/manual/en/reserved.variables.post.php).

If you are trying to alter the html using php based on javascript running in that same page, it's going to be impossible. I recommend using only javascript, not php, in that case.


Well, assuming you have a javascript object e.g

var data = { totalTime: 12, shiftTime: 10 }

You could loop through the data object, create a label and an input for each data item in the array. Let's assume you would like to display this in a div called show_data

for( var i in data ) 
{
   $('#show_data').append( "<label for='"+ i + "'>" + i + "</label>" ); 
   $('#show_data').append( "<input id='"+ i +"' value='"+ data[i] + "' />" ); 
{

Not sure if this is what you were asking. This could be improved a lot but it gives you a rough idea.


It appears that your images.js file is obfuscated. I'm going out on a limb here, but it is possible you are asking about how to access variable names defined in that JS file before it gets compiled. If that is the case I have a few recommendations...

First, don't obfuscate your code like that; it is pointless and affects performance. If that is not an option, it is possible that the obfuscator will let you define specific keywords not to munge; set the variables you want to access in the obfuscator's configuration.

If none of this helps, then you will likely need to post more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消