[Web4lib] library calculator/java question
Richard James
richardjam at gmail.com
Tue Mar 24 08:08:55 EDT 2009
Thanks- I combined some of your input with Andrew Mutch's and got a bare
bones working version up.
It was a bastard to debug, as you suggested. There were also a couple of
results called for in the total that weren't defined as items, and
vice-versa.
Thanks, Web4lib community!
On Mon, Mar 23, 2009 at 8:01 PM, Cloutman, David
<DCloutman at co.marin.ca.us>wrote:
> Probably the biggest problem is that your HTML is mangled. For instance,
> you left out the body tag. That's probably why the interpreter couldn't
> find the function. JavaScript will fail if your HTML is defective
> enough.
>
> I've cleaned up the HTML a bit and commented out everything that threw
> an error in Firefox.
>
> JavaScript is a bastard to debug. However, like most languages, the best
> approach is to comment out everything that throws an error, until the
> thing runs. Then you can go through line by line and fix everything.
>
> I would advise you to use the getElementById() method to access items in
> the DOM consistently.
>
> Here is code that worked in FF and did not throw errors in Firebug. Most
> of it is commented out. Uncomment and fix, and you should be on your
> way. I also would recommend picking up a recent book on JavaScript. The
> language has evolved significantly over the last 10 years, and much of
> what is online is out of date, and no longer works.
>
> <html>
> <head>
>
> </head>
> <body>
> <h1>Library Use Value Calculator </h1><h2>What is your library worth to
> you? </h2>
> <p> How much would you pay out-of-pocket for your library services?</p>
> <ul>
> <li> Enter in the left hand column the number of times <strong>per
> month</strong> you or your family use each service.</li>
> <li>Estimated retail value of each service (if purchased) will be
> calculated on the right.</li>
> <li> Total value of your library use is shown at the bottom of the
> worksheet. </li>
>
> <li><strong>Tip</strong>: Tab between entries and do not use commas.
> </li>
> </ul>
> <form action="javascript:void(0);" method="post" name="calculator"
> id="calculator">
> <table cellspacing="0" class="narrow" id="tbstriped" summary="A
> javascript driven calculator to determine estimated retail value for a
> variety of library services">
> <caption>Value of Library Services </caption>
> <tbody>
> <tr>
> <th scope="col">Input Your <br /> Use</th>
> <th scope="col">Library Services</th>
> <th scope="col">Value of <br /> Services</th>
> </tr>
> <tr>
> <td><input type="text" name="books" id="books"
> size="5" onchange="doCalculator()" tabindex="1" /></td>
> <td><label for="books">Books
> Borrowed</label></td>
> <td><label for="booksResult">$
> <input type="text" id="booksResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="paper" id="paper"
> size="5" onchange="doCalculator()" tabindex="2" /></td>
> <td><label for="paper">Paperback
> Borrowed</label></td>
> <td><label for="paperResult">$
> <input type="text" id="paperResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="child" id="child"
> size="5" onchange="doCalculator()" tabindex="3" /></td>
> <td><label for="child">Children Books
> Borrowed</label></td>
> <td><label for="childResult">$
> <input type="text" id="childResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="magazines"
> id="magazines" size="5" onchange="doCalculator()" tabindex="4" /></td>
>
> <td><label for="magazines">Magazines
> Borrowed</label></td> <td><label for="magazinesResult">$
> <input type="text" id="magazinesResult" size="5" value="0.00"
> /></label></td> </tr> <tr> <td><input
> type="text" name="movies" id="movies" size="5" onchange="doCalculator()"
> tabindex="5" /></td> <td><label for="movies">Movies
> Borrowed</label></td> <td><label for="moviesResult">$
> <input type="text" id="moviesResult" size="5" value="0.00"
> /></label></td> </tr> <tr> <td><input
> type="text" name="audiobooks" id="audiobooks" size="5"
> onchange="doCalculator()" tabindex="6" /></td> <td><label
> for="audiobooks">Audio Books Borrowed</label></td>
> <td><label for="audiobooksResult">$
> <input type="text" id="audiobooksResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="magazineuse"
> id="magazineuse" size="5" onchange="doCalculator()" tabindex="8" /></td>
>
> <td><label for="magazineuse">Magazine/Newspaper
> Use in Library</label></td>
> <td><label for="magazineuseResult">$
> <input type="text" id="magazineuseResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="ill" id="ill"
> size="5" onchange="doCalculator()" tabindex="9" /></td>
> <td><label for="ill">Interlibrary
> Loan</label></td>
> <td><label for="illResult">$
> <input type="text" id="illResult" size="5" value="0.00" /></label></td>
>
> </tr>
> <tr>
> <td><input type="text" name="meetingroom"
> id="meetingroom" size="5" onchange="doCalculator()" tabindex="10"
> /></td>
> <td><label for="meetingroom"> Meeting Room Use
> per Hour</label></td>
> <td><label for="meetingroomResult">$
> <input type="text" id="meetingroomResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="adultprogram"
> id="adultprogram" size="5" onchange="doCalculator()" tabindex="12"
> /></td>
> <td><label for="adultprogram">Adult Programs and
> Classes Attended</label></td>
> <td><label for="adultprogramResult">$
> <input type="text" id="adultprogramResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="childrensprogram"
> id="childrensprogram" size="5" onchange="doCalculator()" tabindex="13"
> /></td>
> <td><label for="childrensprogram">Children's
> Programs Attended</label></td>
> <td><label for="childrensprogramResult">$
> <input type="text" id="childrensprogramResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="computerhours"
> id="computerhours" size="5" onchange="doCalculator()" tabindex="14"
> /></td>
> <td><label for="computerhours">Hours of Computer
> Use </label> (i.e. Internet, MS Word, etc.)</td>
> <td><label for="computerhoursResult">$
> <input type="text" id="computerhoursResult" size="5" value="0.00"
> /></label></td>
> </tr>
> <tr>
> <td><input type="text" name="databases"
> id="databases" size="5" onchange="doCalculator()" tabindex="16" /></td>
> <td><label for="databases">Use of Other Database
> Searching like EBSCO </label></td>
> <td><label for="databasesResult" >$
> <input type="text" id="databasesResult" size="5" value="0.00"
> /></label></td> </tr> <tr> <td><input
> type="text" name="reference" id="reference" size="5"
> onchange="doCalculator()" tabindex="17" /></td> <td><label
> for="reference">Reference Questions Asked</label></td>
> <td><label for="referenceResult">$ <input type="text"
> id="referenceResult" size="5" value="0.00" /></label></td>
> </tr> <tr> <td colspan="3"><hr />
> </td>
> </tr>
>
> <tr>
> <td colspan="2" align="center">
> <input type="button" value="Calculate The Value
> of Your Library Use" onclick="doCalculator()" tabindex="16" />
>
> <span class="button">
> <input type="reset" value="Clear Form" />
> </span>
> </td>
> <td><label for="totalResult">$ <input type="text"
> name="totalResult" id="totalResult" size="5" value="0.00"/></label></td>
> </tr>
> </tbody>
> </table>
> </div>
> </form>
>
> <script type="text/javascript">
> //
> function doCalculator(){
> /*
> var booksValue = document.calculator.books.value * 27.00;
> document.getElementById("booksResult").value = booksValue.toFixed(2);
>
> var paperValue = document.calculator.paper.value * 7.00;
> document.getElementById("paperResult").value = paperValue.toFixed(2);
>
> var childValue = document.calculator.child.value * 20.00;
> document.getElementById("childResult").value = childValue.toFixed(2);
>
> var magazinesValue = document.calculator.magazines.value * 3.50;
> document.getElementById("magazinesResult").value =
> magazinesValue.toFixed(2);
>
> var moviesValue = document.calculator.movies.value * 22.00;
> document.getElementById("moviesResult").value = moviesValue.toFixed(2);
>
> var audiobooksValue = document.calculator.audiobooks.value * 30.00;
> document.getElementById("audiobooksResult").value =
> audiobooksValue.toFixed(2); var
>
> var magazineuseValue = document.calculator.magazineuse.value * 1.00;
> document.getElementById("magazineuseResult").value =
> magazineuseValue.toFixed(2);
>
> var illValue = document.calculator.ill.value * 30.00;
> document.getElementById("illResult").value = illValue.toFixed(2);
>
> var meetingroomValue = document.calculator.meetingroom.value * 50.00;
> document.getElementById("meetingroomResult").value =
> meetingroomValue.toFixed(2);
>
> var auditoriumValue = document.calculator.auditorium.value * 250.00;
> document.getElementById("auditoriumResult").value =
> auditoriumValue.toFixed(2);
>
> var adultprogramValue = document.calculator.adultprogram.value * 10.00;
> document.getElementById("adultprogramResult").value =
> adultprogramValue.toFixed(2);
>
> var childrensprogramValue = document.calculator.childrensprogram.value *
> 6.00;
> document.getElementById("childrensprogramResult").value =
> childrensprogramValue.toFixed(2);
>
> var computerhoursValue = document.calculator.computerhours.value *
> 12.00;
> document.getElementById("computerhoursResult").value =
> computerhoursValue.toFixed(2);
>
> var newsarticlesValue = document.calculator.newsarticles.value * 1.00;
> document.getElementById("newsarticlesResult").value =
> newsarticlesValue.toFixed(2);
>
> var databasesValue = document.calculator.databases.value * 20.00;
> document.getElementById("databasesResult").value =
> databasesValue.toFixed(2);
>
> var referenceValue = document.calculator.reference.value * 15.00;
> document.getElementById("referenceResult").value =
> referenceValue.toFixed(2);
> */
> var totalValue =
> (document.calculator.booksResult.value*1)+
> (document.calculator.paperResult.value*1)+
> (document.calculator.childResult.value*1)+
> (document.calculator.magazinesResult.value*1)+
> (document.calculator.moviesResult.value*1)+
> (document.calculator.audiobooksResult.value*1)+
> //(document.calculator.passesResult.value*1)+
> (document.calculator.magazineuseResult.value*1)+
> (document.calculator.illResult.value*1)+
> (document.calculator.meetingroomResult.value*1)+
> //(document.calculator.auditoriumResult.value*1)+
> (document.calculator.adultprogramResult.value*1)+
> (document.calculator.childrensprogramResult.value*1)+
> (document.calculator.computerhoursResult.value*1)+
> //(document.calculator.newsarticlesResult.value*1)+
> (document.calculator.databasesResult.value*1)+
> (document.calculator.referenceResult.value*1);
> document.getElementById("totalResult").value = totalValue.toFixed(2);
> }
> </script>
> </body>
> </html>
>
>
>
> ---
> David Cloutman <dcloutman at co.marin.ca.us>
> Electronic Services Librarian
> Marin County Free Library
>
> -----Original Message-----
> From: web4lib-bounces at webjunction.org
> [mailto:web4lib-bounces at webjunction.org] On Behalf Of Richard James
> Sent: Monday, March 23, 2009 12:06 PM
> To: web4lib at webjunction.org
> Subject: [Web4lib] library calculator/java question
>
>
> I'm trying to install a "library value calculator" on my own site, with
> next
> to no knowledge of java. Any guidance gladly accepted.
> I carefully cribbed and cleaned up source code from the standard
> calculator
> as provided by Maine, but I'm pretty sure I must be missing something
> important because none of the total fields will calculate at all:
>
> http://lib.de.us/libraryvalue.html
>
> grateful for any help!
>
> Richard James
> _______________________________________________
> Web4lib mailing list
> Web4lib at webjunction.org
> http://lists.webjunction.org/web4lib/
>
>
> Email Disclaimer: http://www.co.marin.ca.us/nav/misc/EmailDisclaimer.cfm
>
>
More information about the Web4lib
mailing list