1

I am adding a text area on click of a particular div. It has <form> with textarea. I want to send the jquery variable to my php page when this submit button is pressed. How can this be achievable. I am confused alot with this . Being new to jquery dizzes me for now. Here is my code,

`

<script type="text/javascript">
$(document).ready(function(){
 $('.click_notes').on('click',function(){
 var tid = $(this).data('question-id'); 
 $(this).closest('ul').find('.demo').html("<div class='comment_form'><form action='submit.php' method='post'><textarea cols ='50' class='span10' name='notes' rows='6'></textarea><br><input class='btn btn-primary' name= 'submit_notes' type='submit' value='Add Notes'><input type='hidden' name='submitValue' value='"+tid+"' /></form><br></div>");
 });
});
</script>`
20
  • whats the result if you are using the above code ? does the form has the question id as hidden ? Commented Jan 18, 2019 at 7:05
  • have you tried ajax call, send your variable with data ? Commented Jan 18, 2019 at 7:05
  • I am not understanding how to move ahead from here. Commented Jan 18, 2019 at 7:05
  • 1
    your code works fine in the fiddle i created. you can check it here jsfiddle.net/xe2Lhkpc Commented Jan 18, 2019 at 7:21
  • 1
    use the name of the inputs as key of $_POST array to get their values. if(isset($_POST['notes'])) { $notes = $_POST['notes']; Commented Jan 18, 2019 at 7:35

2 Answers 2

1

Your code works fine in the fiddle I created here -> https://jsfiddle.net/xe2Lhkpc/

use the name of the inputs as key of $_POST array to get their values.

if(isset($_POST['submitValue'])) { $qid = $_POST['submitValue']; } 

if(isset($_POST['notes'])) { $notes = $_POST['notes']; }
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this. Highly appreciated. One question. How can I show or hide this text area on clicking somewhere on the page or the label
check this fiddle. Added X mark to close. jsfiddle.net/z7wqcdor
Yes its working well but how to align this at right most corner of the text box. Currently it appears at the leftmost corner.
1

You should send your data after form submitted, something like this :

    $(".comment_form form").submit(function(e) {


    var form = $(this);
    var url = form.attr('action');

    $.ajax({
           type: "POST",
           url: url,
           data: form.serialize(), // serializes the form's elements.
           success: function(data)
           {
               alert(data); // show response from the php script.
           }
         });

    e.preventDefault(); // avoid to execute the actual submit of the form.
});

you can assign event after insert your form.

// handling with the promise

$(this).closest('ul').find('.demo').html("<div class='comment_form'><form action='submit.php' method='post'></form><br></div>").promise().done(function () {
       // your ajax call
  });;

1 Comment

This does not shows anything. Rather now i am not obtaining any textarea on click to Add notes div

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.