return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Bootstrap form not calling JS function on submit - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap form not calling JS function on submit - Stack Overflow

programmeradmin1浏览0评论

I have the following code which consists of a form whose on submit calls a javascript function.

<div class="form" role="form" onsubmit="createresult()">
    <fieldset>
    <?php
        $subject = $_GET["sub"];
        $array = mysqli_query($con, "Select * from questions where subject='$subject'");
        $j =1;
        while($row = mysqli_fetch_array($array))
        {
            echo "
            <div class=\"form-group\"><h5>$row[question]</h5>";
                for($i=1;$i<5;$i++)
                {
                    $opt1 = "option".$i;
                    $opt = $row[$opt1];
                    $name = "question" ."$j";
                    echo "
                <label class=\"radio-inline\">
                <input type=\"radio\" name=$name required>$opt</label>";
            }
            echo "</div>";
            $j++;
        }
        ?>

    <button type="submit" class="btn btn-primary" name="submit">Submit</button>
    <button type="reset" class="btn btn-primary">Reset</button>
    </fieldset>
</div>

The PHP script is working fine but this form is not calling the JavaScript function createresult().

I have the following code which consists of a form whose on submit calls a javascript function.

<div class="form" role="form" onsubmit="createresult()">
    <fieldset>
    <?php
        $subject = $_GET["sub"];
        $array = mysqli_query($con, "Select * from questions where subject='$subject'");
        $j =1;
        while($row = mysqli_fetch_array($array))
        {
            echo "
            <div class=\"form-group\"><h5>$row[question]</h5>";
                for($i=1;$i<5;$i++)
                {
                    $opt1 = "option".$i;
                    $opt = $row[$opt1];
                    $name = "question" ."$j";
                    echo "
                <label class=\"radio-inline\">
                <input type=\"radio\" name=$name required>$opt</label>";
            }
            echo "</div>";
            $j++;
        }
        ?>

    <button type="submit" class="btn btn-primary" name="submit">Submit</button>
    <button type="reset" class="btn btn-primary">Reset</button>
    </fieldset>
</div>

The PHP script is working fine but this form is not calling the JavaScript function createresult().

Share Improve this question edited Dec 22, 2014 at 11:08 arshad 8937 silver badges35 bronze badges asked Dec 22, 2014 at 10:39 user3752476user3752476 31 silver badge3 bronze badges 1
  • why not use a <form> tag ? – Hacketo Commented Dec 22, 2014 at 10:41
Add a ment  | 

2 Answers 2

Reset to default 3

https://developer.mozilla/en-US/docs/Web/API/GlobalEventHandlers.onsubmit

The submit event happens when a user clicks a submit button inside a <form> tag. Right now you use a <div> tag.

If you would like to use the <div> tag, instead of using onsubmit, use onclick on the submit

<button type="submit" class="btn btn-primary" name="submit" onclick="createresult()">Submit</button>

Change:

<div class="form" role="form" onsubmit="createresult()">
// your code
</div>

To

<form onsubmit="createresult()">
// your code
</form>
发布评论

评论列表(0)

  1. 暂无评论