如何使用Ajax或Jquery填充文本框中的值?

时间:2021-04-24 03:18:05

Example- Consider three textboxes. In the first one, im providing ID or number ( primary key in my table). Using the ID, the semester and branch should be auto filled using the ID. ( All the three fields are in same table- in my DB). HTML part:

示例 - 考虑三个文本框。在第一个,我提供ID或数字(我的表中的主键)。使用ID,学期和分支应使用ID自动填充。 (所有这三个字段都在我的数据库中的同一个表中)。 HTML部分:

<input type='text'  name='hosteladmissionno'>
   <input type='text'  name='student_name'>
   <input type='text'  name='semester'>

PHP,Mysql part:

PHP,Mysql部分:

<?php
session_start();
   $hostad=$_POST['hosteladmissionno'];
   $sem=$_POST['student_name'];
   $sem=$_POST['semester'];
$r1="INSERT INTO payment(hosteladmissionno)VALUES ('$hostad')";

Now i want the fields student_name and semester to be autofilled for the correspoinding hosteladmissionno. Can this be done by Ajax or Jquery? If so.. How can i implement in this Code? Note: hosteladmissionno,student_name and semester belongs to registration tablem in my database. I need to retrieve the values from that table.Thanks in advance.

现在我希望字段student_name和semester被自动填充为correspoinding hosteladmissionno。这可以通过Ajax或Jquery完成吗?如果是这样..我如何在本规范中实施?注意:hosteladmissionno,student_name和semester属于我的数据库中的注册tablem。我需要从该表中检索值。提前谢谢。

1 个解决方案

#1


1  

What do you mean auto-filled? The query that you've provided only the hosteladmissionno will be inserted. Unless you have a default value for the other column. But if you intended to insert the text you forward, you should also add it in your insert value. Something like this.

你是什​​么意思自动填充?将插入您仅提供hosteladmissionno的查询。除非您有另一列的默认值。但是,如果您打算插入前进文本,则还应将其添加到插入值中。像这样的东西。

$r1 = "INSERT INTO payment(hosteladmissionno, student_name, semester)VALUES ('$hostad','$sem_student_name','$sem_semester')";

I don't know why you use the same variable in two different field. Does only the last initialization will be its value.

我不知道为什么你在两个不同的领域使用相同的变量。只有最后一次初始化才是它的值。

See some tutorials:

看一些教程:

Post MySQL Result Using AJAX via jQuery

通过jQuery使用AJAX发布MySQL结果

JQuery Ajax

JQuery Ajax

PHP tag

PHP标签

jquery -> php -> mysql

jquery - > php - > mysql

#1


1  

What do you mean auto-filled? The query that you've provided only the hosteladmissionno will be inserted. Unless you have a default value for the other column. But if you intended to insert the text you forward, you should also add it in your insert value. Something like this.

你是什​​么意思自动填充?将插入您仅提供hosteladmissionno的查询。除非您有另一列的默认值。但是,如果您打算插入前进文本,则还应将其添加到插入值中。像这样的东西。

$r1 = "INSERT INTO payment(hosteladmissionno, student_name, semester)VALUES ('$hostad','$sem_student_name','$sem_semester')";

I don't know why you use the same variable in two different field. Does only the last initialization will be its value.

我不知道为什么你在两个不同的领域使用相同的变量。只有最后一次初始化才是它的值。

See some tutorials:

看一些教程:

Post MySQL Result Using AJAX via jQuery

通过jQuery使用AJAX发布MySQL结果

JQuery Ajax

JQuery Ajax

PHP tag

PHP标签

jquery -> php -> mysql

jquery - > php - > mysql