dsxon40042 2016-10-20 07:43
浏览 107

在jquery中验证表单数据

i want to validate this from uing jquery. enter image description here

WHEN USER CLick on checkbox and empty textbox it alerts me please fill out answer1 and vice versa for other answers. And another validation user can't select more that two or three checkbox. Here is my Html code:-

<div class="portlet-body form">
    <form id="add-question-form" class="form-horizontal" method="POST" action="{{ url('admin/add-question/'.$course_id) }}" enctype="multipart/form-data">
        <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
        <div class="form-body">
            <div class="form-group">
                <label class="col-md-3 control-label">Question</label>
                <div class="col-md-4">
                    <textarea type="text" placeholder="Enter Question" class="form-control" name="title"></textarea>
                </div>
            </div> 
            @for($i=1; $i <=6; $i++)
            <div class="form-group">
                <label class="col-md-3 control-label">Option {{ $i }}:</label>
                <div class="col-md-4">
                    <input type="text" placeholder="Enter Option {{ $i }} " class="form-control" name="options[{{$i }}]">
                </div>
                <div class="col-md-1" style="float:left;  vertical-align: middle;">
                    <input type="checkbox" id="{{ $i }}" class="form-control" name="is_correct[{{ $i }}]" value = "1">
                </div>
            </div>
            @endfor  
        </div>
        <div class="form-actions fluid">
            <div class="row">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn green" type="submit">Submit</button>
                    <button onclick="window.location.href='/admin/test_questions/{{$course_id}}'" class="btn default" type="button">Cancel</button>
                </div>
            </div>
        </div>
    </form>
</div>

Can anyone provide me jquery code. Thanks in advance

  • 写回答

2条回答 默认 最新

  • doulan8054 2016-10-20 07:49
    关注

    You will have to add an onsubmit attribute to the form like this

    <form onsubmit="return Validate()">
    

    Then the Validate() method will return false if any of the validation fails and prevent the form from being submitted. Now to write Validate method, i suggest you go through the basic syntax of JQuery and believe me it would be very easy to do these validations.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算