Click here to Skip to main content
15,923,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to pass textbox entered value to another page without submit button in Php.

My coding:

XML
<form name="frm1" id="frm1" method="post" enctype="multipart/form-data">
      <label>SEARCH:</label>
      <input name="tag" type="text" id="tag" size="20" />
      <input name="tag1" type="text" id="tag1" size="20" />
      </form>
      <script>
        $(document).ready(function() {
        $("#tag").change(function() {
        $.ajax({
            type: "POST",
            url: "autocomplete1.php",
            data: {
               tag: $("#tag").val()
            },
            success: function(result) {
            alert(tag);
            }
        });
        });
        });
        </script>
Posted
Updated 29-Jan-15 1:23am
v2

It's a basic Idea using this you can pass textbox value from one page to another page using JavaScript and Html....Hope it helps

page1.html:

<html>
<form type=get action="page2.html">
<table>
<tr>
<td>First Name:</td>
<td><input type=text name=firstname size=10></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=text name=lastname size=10></td>
</tr>
<tr>
<td>Age:</td>
<td><input type=text name=age size=10></td>
</tr>
<tr>
<td colspan=2><input type=submit value="Submit">
</td>
</tr>
</table>
</form>
</html>
2)page2.html:

<html>
<script LANGUAGE="JavaScript">
function getParams(){
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++){
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
</script>
</html>
 
Share this answer
 
Comments
Member 12994972 3-Mar-17 10:45am    
i am getting error when i try to display more than three text boxes values ! How to solve this... ????
You are almost there, except the mistake in
alert(tag);

it should be
XML
alert(result);

for example, page1.html:
<html>
<head>
<script>
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<form name="frm1" id="frm1" method="post" enctype="multipart/form-data">
      <label>SEARCH:</label>
      <input name="tag" type="text" id="tag" size="20">
      <input name="tag1" type="text" id="tag1" size="20">
      </input></input></form>
      <script>
        $(document).ready(function() {
            $("#tag").change(function() {
                $.ajax({
                    type: "POST",
                    url: "autocomplete1.php",
                    data: {
                        tag: $("#tag").val()
                    },
                    success: function(result) {
                        // show returned message in a pop up
                        alert(result);
                    }
               });
          });
     });
      </script>
</body>
</html>

To receive the data in autocomplete1.php:
<?php
// capture the sent value from tag and echo back
    $request = $_POST['tag'];
    // code to act on the $request
    // echo back to the calling page
    echo $_POST['tag'];
?>
 
Share this answer
 
v2
Comments
Member 11310933 29-Jan-15 8:15am    
In autocomplete1.php I am not getting tag value.@Peter Leow
Peter Leow 29-Jan-15 10:08am    
Of course, it got the tag value. You can see the value being echo back to the calling page. Ajax will send data but does not redirect to a new page like autocomplete1.php. It you want to redirect to a new page, then you have to use a submit button. Refer: http://www.w3schools.com/php/php_forms.asp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900