Passing 2 values from text form to another page through AJAX

user2691544

I have a text form that contains a text field as well as a designated ID number that i would like to send over to another page. Would that be possible ?

<form name="cForm" id="cForm">
            Comment: <input type="textBox" name="cText" id="cText" />
            <input type="button" name="submitCreate" id="submitCreate" value="Create" onclick="showCreate('.$row['ID'].')" /><br>
        </form>

<script>
function showCreate(str) {
  if (str=="") {
    document.getElementById("showCreate").innerHTML="";
    return;
  } 
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      document.getElementById("showCreate").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("Post","showCreate.php?q="+str,true);
  xmlhttp.send();
}
</script>

i would like to get the value of the text field and ID in separate variables as such

$comment = $_REQUEST["q"];
$ID = $_REQUEST["p"];
volkinc

not sure that i understand you right but try this:

<form name="cForm" id="cForm">
            Comment: <input type="textBox" name="cText" id="cText" />
            <input type="button" name="submitCreate" id="submitCreate" value="Create" onclick="showCreate('.$row['ID'].')" /><br>
        </form>

<script>
    function showCreate(str) {
      if (str=="") {
        $("#showCreate").html("");
        return;
      } 
    $.ajax({
        type: "POST",
        url: "showCreate.php",
        data: "q="+str+"&p="+$("#cText").val()
        }).done(function( result ) {
             $("#showCreate").html(result);
        });
    }
</script>

so you gonna be able to use vars at php like you wanted

$comment = $_REQUEST["q"];
$ID = $_REQUEST["p"];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

passing data through text box from select option into another page

Passing form values through AJAX to php

Passing text from textarea through ajax

WinForms - Passing values from one Form to another

Sending data from the form to an email with jQuery ajax and redirect to another page with passing POST variables not work

Passing Variable through JavaScript from one html page to another page

passing values from one page to another page using jquery

Passing querystring from one page to another through javascript

Ajax is not passing variable to another page?

Passing Data from one form to another form in Yii2

Passing values from one model to another's form

Passing link text from a hyperlink to another page. (Express JS)

Stop page from redirecting after submitting google form through AJAX

Passing Values from (DataGridView1_Click) in a Form to another sub in another form

Passing a datagridview from another form

Passing multiple data values through AJAX data

Passing unique input values through ajax not working

Passing 2 values to a js function from an HTML form using $_POST

Display form input values from one page to another

passing 2 values from dropdown in php using ajax

passing values from jframe to another

pass values from one PHP page to another with ajax

passing form data to another HTML page

Passing values from form1 to form2 via button click to form2

Form submission through ajax and reply from servlet through JSON without page refresh

VB.Net Passing values to another form

cannot pass values from text box to display it in another HTML page

php page accessible only by passing through another php page

mysql insert into select join - copy values from one column to another table, passing through a connecting table