Jump to content

AJAX for Updating Info on the Page


LeMen

Recommended Posts

Hello.

 

I am beginner try to learn something new. I have wish, "how to" below... ::)

 

1. Let's say I have table within database which hold "ID" information. It's numeric, and I have input form.

When the form is display, I have HTML code showing the "current" ID which is the last ID in the table, plus 1. So, if the last one is 12, then its shown 13, and soon.

How I achieve this code to be done ?

 

2. I got table consist of "Name", "Address", "Age"

I have option code, like this:

<select name="nameID">
 <option value="Mr. Alpha">Mr. Alpha</option>
 <option value="Mrs. Beta">Mrs. Beta</option>
 <option value="Ms. Gamma">Ms. Gamma</option></select>

Upon user selected on of those option, I want to show the correspondent value within the database, which are "Address" and "Age", on the specific position within the form.

How I done this purpose?

 

Appreciate for your time and effort. Thanks in advance. :)

Link to comment
https://forums.phpfreaks.com/topic/284160-ajax-for-updating-info-on-the-page/
Share on other sites

The associated event for selecting <option> tags is "onchange".

 

Assuming you are using jQuery for Ajax purposes (you really should), you could do this.

 

$("select[name='nameID']").on("change",function(){
 var current = $(this).find("option:selected");
 $.post("/scriptUrl.php",{val:current.attr("value")},function(d){
  current.after(d);
 });
});
Untested because I cannot test my code just yet on my phone (refer to my signature if you need to).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.