HTML函数调用不起作用

时间:2015-10-30 09:48:05

标签: javascript html

我一直在让startform()函数在我的下面的HTML中工作时遇到问题。我可以使用no wrap选项让它在JFIDDLE中工作。任何想法为什么我的函数调用不起作用我已经单独测试了JavaScript代码,它的工作原理。

    <html>
<title>Paycheck Calculator</title>
    <link rel="stylesheet" href="pay.css" type="text/css">
    <script src="midterm.js"></script>
</head>
<body>
<form name="paycheck">
<table width=80% align="center" >
    <tr>
        <td colspan="2"><h1>Your Paycheck Calculator</h1></td>
        <!-- FORM DATE -->
        <td colspan="2"><h2 align="right">Date: <input type="text" id ="formdate" class="date" name="formdate" size="10"></h2></td>
        <td><input type="button" onclick="startform();" value="test"></input></td>
    </tr>
    <tr>
        <td colspan="4">This Paycheck Calculator has been provided for you by your
        Human Resources Department. You can use it to figure out your upcoming paycheck
        or to see what impact the following changes would make on your paycheck: if
        you change the number of dependents on you W-2, if you increase or decrease your
        working hours, or if you get a raise. <br /></td>
    </tr>
    <tr>
        <td colspan="4"><hr /></td>
    </tr>
    <tr>
        <td class="smallcell">&nbsp;</td>
        <td class="bordrlft"><p class="rght">Hourly Pay Rate:<br /></p></td>
        <td class="bordr"><input name="payrate"></td>
        <td class="bigcell">&nbsp;</td>
    </tr>
    <tr>
        <td class="smallcell">&nbsp;</td>
        <td class="bordrlft"><p class="rght">Number of hours <br />
        worked this week: </p></td>
        <td class="bordr"><input name="hours" ></td>
        <td class="bigcell">&nbsp;</td>
    </tr>
    <!--<tr>
        <td class="smallcell">&nbsp;</td>
        <td valign="top" class="bordrlft"><p class="rght">How many <br />
        dependents do<br /> you claim on <br />your taxes?</p></td>
        <td class="bordr">
            <input type="radio" name="tax0" value="zero" onclick="tax_percent();">0<br />
            <input type="radio" name="tax1" value="one" onclick="tax_percent();">1<br />
            <input type="radio" name="tax2" value="two" onclick="tax_percent();">2<br />
            <input type="radio" name="tax3" value="threefour" onclick="tax_percent();">3 - 4<br />
            <input type="radio" name="tax4" value="fivesix" onclick="tax_percent();">5 - 6<br />
            <input type="radio" name="tax5" value="oversix" onclick="tax_percent();">more than 6<br />
        </td>
        <td class="bigcell">&nbsp;</td>
    </tr>-->
    <tr> 
        <td colspan="4"><hr /></td>
    </tr>
    <tr>
        <td colspan="2" align="right" class="rght">Your tax rate is: </td>
        <td colspan="2" ><input type="text" name="feedback" value="" size="20" ></td>
    </tr>
    <tr>
        <td colspan="2" align="right" class="rght">Your paycheck will be: </td>
        <td colspan="2"><input type="text" name="feedback3" value="" size="20"></td>
    </tr>
    <tr>
        <td class="smallcell">&nbsp;</td>
        <td colspan="2" class="rght"><!-- here is the reset buttons--> 
        <p> <input type="reset" value="clear" name="reset"></p></td>
        <td class="smallcell">&nbsp;</td>
    </tr>
</table>
</form>
</body>
</html>

-------- JavaScript代码------

function today(){ 
    var date = new Date();
    var day = date.getDate();
    document.getElementById("formdate").value = day;
    }
    /*function to get date to load on startup */
function startform(){  
    today();
    /*function to display calculated amount in 2-decimal format */
    }

1 个答案:

答案 0 :(得分:0)

所以我把它缩小到JavaScript / HTML文件中的某些内容,导致我发现问题我认为我已经找到了问题。我能够删除我的HTML中的所有内容,并能够让它工作。这也只是一个更大项目的一小部分。谢谢你输入

新代码

Spree::Order::PAYMENT_STATES = %w(balance_due checkout completed credit_owed failed paid pending processing void post_pay).freeze

Javascript

<html>
<head>
<title>Paycheck Calculator</title>
    <link rel="stylesheet" href="pay.css" type="text/css">
    <script src="midterm.js"></script>

</head>
<body>
<form name="paycheck" onclick="startform();">
<table width=80% align="center" >
    <tr>
        <td colspan="2"><h1>Your Paycheck Calculator</h1></td>
        <!-- FORM DATE -->
        <td colspan="2"><h2 align="right">Date: <input type="text" id ="formdate" class="date" name="formdate" size="10"></input></h2></td>
    </tr>
    </table>
    </form>
</body>
</html>