douya1855 2014-12-19 04:57
浏览 33
已采纳

表单的CSS问题

a beginner here. I am dealing with a form that the user chooses an option in a form and clicks on the button. In the back end some actions will be performed and the result will be some text that will appear EXACTLY inside the form. Here is my code:

  <form name="my_form" id="input" style = "background-color: #e1dddd; padding: 10px; border-radius: 5px;" action="actionpage.php" method="post">
        <div class="row" id="output">            
            <div class="container">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                      <label>Title of the form</label><br><br>                 
                      <label>Choose a functionality</label><br>
                      <select name="message">
                            <option value="functionality 1">Choose One</option>
                            <option value="functionality 2">Choose One</option>
                      </select><br>
                      <button type="initiate" name="" id="" value="Initiate" class="btn btn-primary btn-lg">Initiate</button>
                    </div>
                </div>
            </div> 
        </div>
    </form>

<script type="text/javascript"> //this is to stop the form to go to another page

    $(document).ready(function () {
        $('#my_form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "GET",
                data: $(this).serialize(),
                success: function (data) {
                    $("#output").html(data);
                },
                error: function (jXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
    });
    </script> 

And the actionpage.php has below code:

<?php
//some action happening here.
?>

<form name="my_form2" id="" style = "background-color: #e1dddd; padding: 10px; border-radius: 5px;" action="" method="post">
    <div class="row">            
        <div class="container">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                  <label>Text will appear here.</label><br>
                  <label>Text will appear here.</label><br>      
                  <label>Text will appear here.</label><br>
                </div>
            </div>
        </div> 
    </div>
</form>

Now the problem is that the text that will appear inside the form (after performing the actions) is not sitting properly in the form. Some of the text goes out side the form from left side.

I appreciate any suggestion, code sample and guidance.

  • 写回答

1条回答 默认 最新

  • dounieyan2036 2014-12-20 21:04
    关注

    Your ajax is referencing the wrong id for your form.

    <!-- notice your id is input. In your ajax it is using my_form -->
    <form name="my_form" id="input" 
    

    Secondly your ajax is putting the text in an id of #output, but no HTML has that id that you posted.

    Here is a CodePen with a working sample. Hopefully it solves the weird width issue you are facing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题