除非更改输入,否则提交按钮不起作

时间:2011-03-23 17:28:24

标签: javascript html

我有一个表单计算器,当客户提交表单(input.php)时,它会打开另一个页面显示结果(output.php target _blank)。但是,当他们想要使用相同的页面(input.php)再次获得结果时,提交按钮不再工作,除非他们在输入字段中更改了某个值,并且对于下拉菜单,提交按钮赢了工作,甚至你改变了下拉值。

有人可以帮我解决问题吗?谢谢。我只想让按钮一直处于启用状态,这里是input.php的部分代码。

<form name="form1" action="output.php" method="post" target="_blank">
<table id="distax" width="750">
<th colspan="6">F. Discount & Taxes</th>
<tr> 
    <td width="120"><b><input type="radio" name="discountmu" id="disc" value="-" />Discount (-)<br /> <input type="radio" name="discountmu" id="mu" value="+" />Markup (+)</b></td> 
    <td width="80">% <input type="text" name="discmuv" size="3" value="0"></td>
    <td width="120"><b>2. Tax Goods:</b></td>
    <td width="80">% <input type="text" name="txgood" size="3" value="0" onkeyup="data_change(this);"></td>
    <td width="120"><b>3. Tax Services:</b><br />(for items in G)</td> 
    <td width="*">% <input type="text" name="txservice" size="3" value="0" onkeyup="data_change(this);"></td>
</tr> 

<table id="extra" width="750">
<th colspan="6">E. Extras</th>
<tr>
    <td width="170"><b>1. Extra railing (total):</b></td>
    <td width="70"><input type="text" name="extrail" size="2" value="0" onkeyup="data_change(this);">ft</td>
    <td width="110"><b>2. Custom Color: </b></td>
    <td width="*"><select size="1" value="<?=$_SESSION['name']?> " name="R4" id="R4" onchange="showme()">
        <option selected value="noSS">Sand Stone (Ral 1019)</option>
        <option value="noEW">Euro White (Ral 9010)</option>
        <option value="noQG">Quartz Grey (Ral 8014)</option>
        <option value="noJB">Java Brown (Ral 8014)</option>
        <option value="yes">Custom</option>
        </select>
        <input type="text" id="color1other" name="color1other" style=" position:relative;display:none;" Size=20 value="enter custom color here">
    </td>
</tr>
<tr>
    <td width="170"> <b>3. Height adjustment [ft // cm]:</b></td>
    <td width="*">
    <select size="1" name="D8">
        <option value="1.125">+2'6&quot; // +76cm</option>
        <option value="1.1">+2'0&quot; // +61cm</option>
        <option value="1.075">+1'6&quot; // +46cm</option>
        <option value="1.05">+1'0&quot; // +30cm</option>
        <option value="1.025">+0'6&quot; // +15cm</option>
        <option selected value="1">0</option>
        <option value="0.985">-0'6&quot; // -15cm</option>
        <option value="0.97">-1'0&quot; // -30cm</option>
        <option value="0.955">-1'6&quot; // -46cm</option>
        <option value="0.94">-2'0&quot; // -61cm</option>
        <option value="0.925">-2'6&quot; // -76cm</option>
        <option value="0.91">-3'0&quot; // -91cm</option>
      </select>
    </td>
        <td width="110"><b>4. Freight (Sea/Land/Air): </b></td>
        <td width="*">
        <input type="text" id="freight" name="freight" Size=12 value="0"><b>USD</b>
    </td>
</tr>

<input type="Submit" Value="Get your quote"> as
<input type="radio" value="detail" checked name="report">Dealer <input type="radio" name="report" value="short"> Client version in English
</form>

感谢您的回复,这里是javascript的代码,没有看到任何与提交按钮相关的内容

//Date: 05/27/2009 Edited by EG

function reload(form)
{

var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val3=document.form1.load.value;
//Date: 07/27/2009 Edited by EG
//self.location=self.location + '&cat=' + val + '&load=' + val3;
//self.location='webcalc_input.php?PHPSESSID=' + ssidjs + '&cat=' + val + '&load=' + val3;
self.location='webcalc_input.php?cat=' + val + '&load=' + val3;
}

function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 
var val3=document.form1.load.value;
//Date: 07/27/2009 Edited by EG
self.location= 'webcalc_input.php?cat=' + val + '&cat3=' + val2 + '&load=' + val3;
//self.location='webcalc_input.php?PHPSESSID=' + ssidjs + '&cat=' + val + '&cat3=' + val2 + '&load=' + val3;
}

function data_change(field) {
    var check = true;
    var value = field.value; //get characters
    //check that all characters are digits, ., -, or ""
    for (var i = 0; i < field.value.length; ++i) {
        var new_key = value.charAt(i); //cycle through characters
        if (((new_key < "0") || (new_key > "9")) && !(new_key == "") && (new_key != ".")) { //Included . to enable decimal entry
            check = false;
            break;
        }
    }
    //apply appropriate colour based on value
    if (!check) {
        field.style.backgroundColor = "red";
    }
    else {
        field.style.backgroundColor = "white";
    }
}

function validateEmpty(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow';
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;
}

1 个答案:

答案 0 :(得分:0)

文本输入包含一个javascript函数,您不会在名为data_change()的代码中显示该函数。如果我理解了这个问题,那么该功能可能会禁用提交按钮并在文本更改时启用它。这只是一个没有看到你的javascript代码的假设。

enter code here

找到data_change()函数的定义,并查找与提交按钮相关的内容并将其注释掉。

您可以从onkeyup="data_change(this);"标记中删除<input>,但这可能会破坏其他功能!