【问题标题】:Trying to push a dynamic textarea to mysql using php尝试使用 php 将动态文本区域推送到 mysql
【发布时间】:2012-08-30 02:42:06
【问题描述】:

我快到了,可以尝尝了,但我无法将这最后一小部分转移到 getpost.php。基本上我有动态文本区域,用户可以在其中添加步骤。假设他们添加了 5 个步骤,我需要通过 PHP 将这些步骤添加到 mysql 数据库中。我不确定执行此操作所需的 php。任何帮助我将不胜感激!

这是我的 post.php 的步骤:

<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

var counter = 2;

$("#addButton").click(function () {

if(counter>10){
        alert("Only 10 textboxes allow");
        return false;
}   

var newTextBoxDiv = $(document.createElement('div'))
     .attr("id", 'TextBoxDiv' + counter);

newTextBoxDiv.after().html('<p><label>Step #'+ counter + ' : </label><br>' +
      '<textarea rows="10" cols="150" type="text" name="textbox' + counter + 
      '" id="textbox' + counter + '" value="" >');

newTextBoxDiv.appendTo("#TextBoxesGroup");


counter++;
 });

 $("#removeButton").click(function () {
if(counter==1){
      alert("No more steps to remove");
      return false;
   }   

counter--;

    $("#TextBoxDiv" + counter).remove();

 });

 $("#getButtonValue").click(function () {

var msg = '';
for(i=1; i<counter; i++){
  msg += "\n Step #" + i + " : " + $('#textbox' + i).val();
}
      alert(msg);
 });




});
</script>

</head>

<body>
Add new step below:<p>

<form action="getpost.php" method="post">
<div id='TextBoxesGroup'>
<div id="TextBoxDiv1">
    <label>Step #1 : </label><br />
    <textarea rows="10" cols="150" type='textbox' id='textbox1'></textarea>
</div>
</div>
<input type='button' value='Add Step' id='addButton'>
<input type='button' value='Remove Step' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>
<input type="submit" />
</form>


</body>

【问题讨论】:

标签: php mysql dynamic textarea


【解决方案1】:

你可以使用jquery的clone方法来实现文本框的动态创建。 试试这个:

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">   </script>
<script>
$(document).ready(function(){
var counterb = 1;
$("#addathletehistory").click(function(){
if(counterb>6){
        alert("Maximum 5 textarea allow");
        return false;
}   
$("#sport_history").clone().attr({"id":"sport_history"+counterb, "name":"sport_history"+counterb}).add("<br/>").appendTo("#stablehistory");
counterb++;
  });
});

此 jquery 代码通过单击“添加更多”按钮创建 5 个文本区域。请注意,每个新文本区域的 id 和名称都会随着我向其添加计数器的值而更改。 希望它有所帮助。 编码愉快!

【讨论】:

    猜你喜欢
    • 2012-12-26
    • 2020-01-04
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    相关资源
    最近更新 更多