-3

これは、私が持っているサイトのフォームの下部です。TOS 契約チェックボックスを追加する前は、すべて正常に機能していました。これで、ボックスがオンになっているかどうかに関係なく、ボックスをオンにする必要があることがユーザーに警告されます。どんな助けでも大歓迎です。

<input type='checkbox' value='yes' name='tosagree' id='tosagree'> <p>I have read and agree to the privacy policy and terms of use found on this site.</p>
            <input type='submit' id='submit' name='submit' value='submit'><br /><br />
    </form>
</div>

<script type='text/javascript'>
function validateForm()
{
var asking=document.forms["form"]["asaskingprice"].value,
reasons=document.forms["form"]["asreasons"].value,
timelines=document.forms["form"]["astimelines"].value,
sources=document.forms["form"]["assources"].value,
tos=document.forms["form"]["tosagree"].value;
if (asking==null || asking=="")
  {
  alert("Asking price must be filled out");
  return false;
  }
if (reasons==null || reasons=="")
  {
  alert("reasons must be filled out");
  return false;
  }
if (timelines==null || timelines=="")
  {
  alert("timelines must be filled out");
  return false;
  }
if (sources==null || sources=="")
  {
  alert("sources must be filled out");
  return false;
  }
if (document.forms["form"]["tosagree"].Checked!=true)
  {
  alert("You must agree to the terms of service");
  return false;
  }
}
</script>
4

2 に答える 2

5

正しい属性名はcheckedではなくCheckedです。

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-checked

于 2013-06-25T21:40:35.667 に答える
0

次のように、ID で吸盤を取得できます。

var tos = document.getElementById('tosagree');

if (tos.checked) {
    //return true
}
于 2013-06-25T21:41:22.020 に答える