简体   繁体   English

文本区域表单字段未将值传递给JavaScript

[英]Text area form field not passing value to JavaScript

I have a form on my website which passes its values to some JavaScript which then passes the information to a PHP page to update the database. 我的网站上有一个表单,该表单将其值传递给一些JavaScript,然后将这些信息传递给PHP页面以更新数据库。 When the form is submitted all of the values are added to the database except the two fields which are text areas. 提交表单后,除两个字段即文本区域外,所有值都将添加到数据库中。

If I remove the JavaScript and add a simple form action to directly pass the variables to the PHP page then all of the information is added to the database including the two text area fields and so it seems the problem must be in theform and the JavaScript, otherwise the two fields wouldn't get added to the database regardless. 如果我删除JavaScript并添加一个简单的表单操作以将变量直接传递到PHP页面,则所有信息都将添加到数据库中,包括两个文本区域字段,因此看来问题一定出在表单和JavaScript上,否则,这两个字段将不会添加到数据库中。

Below is my form and my JavaScript. 以下是我的表格和我的JavaScript。 ( Top keep it simple I have only included the two elements of the form which have the problems as it is a long form, if this is the wrong approach then please let me know.) (简单起见,我只包含了表单中的两个元素,因为这是一个长格式,如果这是错误的方法,请告诉我。)

    <form action="" method="post" class="save">
        <label class="col-sm-3 control-label">Notes</label>
        <textarea name="notes" rows="10" class="form-control"></textarea>
        <input type="submit" name="submit" class="save" value="Save This Job" id="blue"/>
     </form>

And now the JavaScript 现在是JavaScript

    $(document).ready(function(){
    $('form.save').submit(function () {
    var ref_number = $(this).find("[name='ref_number']").val();
    var job_title = $(this).find("[name='job_title']").val();
    var start_date = $(this).find("[name='start_date']").val();
    var closing_date = $(this).find("[name='closing_date']").val();
    var category = $(this).find("[name='category']").val();
    var location = $(this).find("[name='location']").val();
    var salary = $(this).find("[name='salary']").val();
    var client = $(this).find("[name='client']").val();
    var job_description = $(this).find("[name='job_description']").val();
    var license = $(this).find("[name='license']").val();
    var notes = $(this).find("[name='notes']").val();
         // ...
        $.ajax({
         type: "POST",
         url: "save.php",
         data: {
              ref_number : ref_number,
              job_title : job_title,
              start_date : start_date,
              closing_date : closing_date,
              category : category,
              location : location,
              salary : salary,
              client : client,
              job_description : job_description,
              license : license,
              notes : notes,

                  },
                  success: function(){
                  new PNotify({
                    title: 'Job Posted',
                    text: '
                    type: 'success',
                     shadow: true
                });


                    }
                      });
                    this.reset();
                    return false;
                      });
                  });

So here is a simplified version of the PHP which I keep changing, as I said above if I send the variables direct to the PHP page all of the information is added to the mysql database, no problems, but when using the JavaScript the job description and notes fields do not get added. 因此,这是我不断更改的PHP的简化版本,如上所述,如果我将变量直接发送到PHP页面,则所有信息都将添加到mysql数据库中,没有问题,但是当使用JavaScript时,作业说明和注释字段不会添加。

      $ref_number = $_POST['ref_number']; 
      $job_title = $_POST['job_title'];
      $start_date = $_POST['start_date']; 
      $closing_date = $_POST['closing_date'];
      $category = $_POST['category']; 
      $location = $_POST['location'];
      $salary = $_POST['salary'];
      $client = $_POST['client'];
      $job_description = $_POST['job_description'];
      $license = $_POST['license'];
      $posted_by = $_POST['posted_by'];
      $site_id = $_POST['site_id'];
      $notes = $_POST['notes'];

      mysql_query("INSERT INTO joborders 
      (ref_number, job_title, start_date, closing_date, category, location, salary, client_name, job_description, license_required, site_id, posted_by, status, notes, posted_date) VALUES('$ref_number', '$job_title', '$start_date', '$closing_date', '$category', '$location', '$salary', '$client', '$job_description', '$license', '$site_id', '$posted_by', 'open', '$notes',  NOW()) ") 
      or die(mysql_error());

So i found the problem, at the bottom of the page was this piece of code, which i hadn't noticed before even though i have looked at it a dozen times. 因此,我发现了问题所在,在页面底部是这段代码,即使我看了十几遍,也没有发现过。 As soon as i removed it, it worked, so now i just need to work out if i can incorporate it on to the existing code so i can still use the tnymce 我一删除它,它就起作用了,所以现在我只需要弄清楚是否可以将其合并到现有代码中,这样我仍然可以使用tnymce

    tinymce.init({
   selector: "textarea"
   });

OK so the problem turned out to be because there was this piece of code on the page 好的,问题出在这是因为页面上有这段代码

    tinymce.init({

selector: "textarea" }); 选择器:“ textarea”});

So i changed this to reference the class of the text are in the form, like this. 所以我将其更改为以此类形式引用文本的类。

 tinymce.init({
selector: "textarea.form-control",

}); });

And now all of the form fields post to the database. 现在,所有表单字段都将发布到数据库中。

Thanks for all your suggestions and comments, much appreciated. 感谢您的所有建议和意见,非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javascript在IE中的表单中设置文本区域值 - How to use javascript to set text area value in a form in IE 表单文本输入字段值不随 javascript 改变 - form text Input field value not changing with javascript 如何通过在Rails 4.0中使用javascript单击复选框将文本区域字段值复制到另一个文本区域字段 - how to copy a text area field value to another text area field by clicking on the check box using javascript in rails 4.0 使用php codeigniter将计算出的javascript变量值传递到文本字段 - Passing calculated javascript variable value to text field using php codeigniter 将带有PHP变量名称的文本字段的值传递给Javascript - Passing value of text field, with a PHP variable name, to Javascript javascript通过隐藏字段传递值 - javascript passing the value with hidden field 使用javascript在clonable表单文本字段中插入值 - Insert a value in clonable form text field using javascript 使用javascript获取文本字段的值,并将其发布到表单的操作中 - get the value of text field using javascript and post it in action of the form 将值放入文本字​​段时的javascript自动提交表单 - javascript autosubmit form when dropping value into text field JavaScript-如果在表单的文本字段中更改了默认值,则强制重定向 - JavaScript - Forcing redirect if default value is changed in text field on a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM