How can get html element value in php?

In the past, whenever I needed to get the value of an html element, I would always submit a form to load a different page. Something like:

page1.php


   

page2.php


My question is, is it possible to get the value of 'input1' on the same page [page1.php] without requiring clicking a submit button?

Deduplicator

43.6k6 gold badges62 silver badges110 bronze badges

asked Sep 14, 2011 at 1:29

With jQuery:

 
 
 
 
 
 
 

Response from server:
$.post['test.php',{'data': "value1"}, function [data] { $['#response'].text[data]; }];

Non-jQuery IE doesn't have the XMLHttpRequest object so here is a shim for IE:

Yes, using ajax / javascript:

var formData = new FormData[];

formData.append["input1", "value1"];

var xhr = new XMLHttpRequest[];
xhr.open["POST", "page1.php"];
xhr.send[formData];

if [typeof XMLHttpRequest == "undefined"] XMLHttpRequest = function[] {
    try {
        return new ActiveXObject["Msxml2.XMLHTTP.6.0"];
    }
    catch [e] {}
    try {
        return new ActiveXObject["Msxml2.XMLHTTP.3.0"];
    }
    catch [e] {}
    try {
        return new ActiveXObject["Microsoft.XMLHTTP"];
    }
    catch [e] {}
    //Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant
    throw new Error["This browser does not support XMLHttpRequest."];
};

answered Sep 14, 2011 at 1:31

JoeJoe

78.4k18 gold badges125 silver badges143 bronze badges

11

What for? Do you want to submit it to another file without needing to actually "submit" the form?

You use JavaScript for that.

document.form1.input1.value

answered Sep 14, 2011 at 1:32

Rolando CruzRolando Cruz

2,7841 gold badge15 silver badges24 bronze badges

2

September 27, 2021 Category : PHP

Hello,

In this example, i will show you php get html tag value example. We will look at example of php get html element value by id. In this article, we will implement a php get html element value. This post will give you simple example of how to get html tag value in php.

Here, i will give you simple two examples how to get html tag value in php and another how to get value by id in php. so let's see both code and output as bellow:

PHP Get HTML Element Value

index.php

Chủ Đề