简体   繁体   English

如何将动态ID文本框值传递给另一个页面而不用jquery和php刷新

[英]How to pass dynamic id text box value to another page without refreshing with jquery and php

$('.btncomment').click(function () {
    var id = $(this).attr('id');
    $.post('SaveTopicInformation.php', {
        tid: commentform.(topic_ + id).value,
        topicdetail: commentform.(topicdetail_ + id).value,
        userid: commentform.(user_ + id).value
    });
});

I have to pass the 3 text box value to another page. 我必须将3文本框的值传递给另一页。 First of all, I display the all the record from database. 首先,我显示数据库中的所有记录。 then, I have comment link for each row. 然后,我在每一行都有评论链接。 I like to give comment and save the comment for eache record. 我喜欢发表评论并将评论保存为每个记录。 I use by jquery and php. 我用jQuery和PHP。 please help me out. 请帮帮我。 I can't finger out how to pass dynamic text box's value by bynamic name. 我不知道如何通过bynamic名称传递动态文本框的值。

You cannot access object fields like that. 您不能访问这样的对象字段。 You need to use the array subscript syntax: 您需要使用数组下标语法:

$.post('SaveTopicInformation.php', {
    tid: commentform['topic_' + id].value,
    topicdetail: commentform['topicdetail_' + id].value,
    userid: commentform['user_' + id].value
});

Actually, since you are using jQuery, using .val() on a jQuery object wrapping the form element would be much nicer. 实际上,由于您使用的是jQuery, .val()在包装表单元素的jQuery对象上使用.val()会更好。

Try this code sample. 试试这个代码示例。 What it does is listen for your submit button to be pressed, then it grabs all of the content from a certain form, and submits it to a server: 它的作用是侦听要按下的“提交”按钮,然后从某个表单中获取所有内容,然后将其提交到服务器:

//Listen for the submit button to be clicked
$('.btncomment').click(function () {
  $.ajax({
    'url' : 'SaveTopicInformation.php', //Processor URL
    'type' : 'POST',                    //Send as POST-data
    'data' : $('.myForm').serialize();  //Send the entire form
    'success' : function(data) {        //What to do when the form is submitted
      if (data == 'success') {
        alert('Form submitted!');
      }
    }
  });
});

Hope that helps, 希望能有所帮助,
spryno724 spryno724

暂无
暂无

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

相关问题 如何将动态文本框值传递给另一个PHP页面 - How to pass the dynamic text box value to another php page 如何在PHP中使用ajax jquery将列表框值发送到另一个列表框而不刷新页面 - How can send one list box value to another list box without refreshing page using ajax jquery in php 如何在不刷新页面的情况下在 php function 中传递来自 url 的 id? - How to pass the id from url in php function without refreshing the page? 如何在不提交表单或刷新页面的情况下将jquery中的变量值传递给PHP? - How do I pass value of a variable in jquery to PHP without submitting form or refreshing the page? 如何使用PHP将在文本框中输入的数据传递到另一个页面 - How to pass data entered on a text box into another page using PHP 将文本框值传递给另一页 - Pass Text-box Value to Another Page jQuery将动态元素ID /值传递给PHP - jQuery pass dynamic element id/value into PHP 如何在不刷新页面的情况下显示名称值而不是该值的ID(使用jQuery) - How to display a name value instead of the ID of that value without refreshing the page (using jQuery) 如何在下拉框中获取列中其他值而不刷新PHP Ajax MySQL中的页面 - How to get the column other value in dropdown box without refreshing the page in php ajax mysql 根据另一个下拉列表的值加载下拉列表-无需刷新PHP页面 - Load dropdown according to the value of another dropdown - without refreshing the page in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM