我有一个选择标签和 2 个输入字段。我想验证输入字段,但每次我按下“Godkend”按钮时,它都不会验证,甚至不会读取 javascript 函数。为什么会这样?
<div class="well">
<div class="row-fluid">
<div class="span3">
<div class="input-holder">
<select name="rest_id" form="carform">
<?php foreach ($dropdownArray as $key):?>
<option placeholder="rest_id*" id="rest_id" name="rest_id" value="<?=$key['restid']; ?>"> <?= $key['restaurantnavn']; ?> </option>
<?php endforeach;?>
</select>
</div>
</div>
<form name="myForm" action="" onsubmit="return validateForm()" id="carform">
<div class="span3">
<div class="input-holder">
<input type="text" class="form-input" id="membernumber" name="membernumber" autocomplete="off" placeholder="Medlems. Nr.*" value="">
</div>
</div>
<div class="span3">
<div class="input-holder">
<input type="text" class="form-input" id="subtotal" name="subtotal" autocomplete="off" placeholder="Beløb.*" value="">
</div>
</div>
<div class="span3">
<div class="input-holder">
<input type="submit" value="Godkend">
</div>
</div>
</form>
</div>
</div>
<script>
function validateForm()
{
var field1=document.forms["myForm"]["membernumber"].value;
var field2=document.forms["myForm"]["subtotal"].value;
var myLength = $("#membernumber").val().length;
if (field1==null || field1=="")
{
alert("something A");
return false;
}
if (myLength < 8 || myLength > 8)
{
alert("something B");
return false;
}
if (field2==null || field2=="")
{
alert("something C");
return false;
}
else
{
alert("something D");
return true;
}
}
</script>