0

I have a hidden field where the question_id is unique. I am trying to get that hidden field within jquery from the next page so that I can post a message of the form status.

Then I will put that status in the HTML at the bottom of the form that was submitted.

form.php

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery File Upload</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script>

    function submitForm(upload_input_field){
        upload_input_field.form.submit();
        return true;
    }
    $(function () {
    });
  </script>
</head>
<body>
    <form action="uploadFile.php" target="uploadIframe" method="post" enctype="multipart/form-data">
        <input type='button' class='btn btn-default' onClick='submitForm(this)' value='Submit' />
        <input name='question_id' value='123' type='hidden' />
    </form>
    <iframe style="border:0;" id="uploadIframe" name="uploadIframe"></iframe>
    <div id="successMessage123"></div>
</body>
</html>

uploadFile.php

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
         $("[name=question_id]").val(var questionid);
        //alert(question_id);
        //$(('#successMessage_'+question_id), window.parent.document).html('<p>hidden value success</p>');
        $('#successMessage_'+question_id).html('<p>hidden value success</p>');
    });
</script>
  • 1
    You cant read the parameter with JQuery, see this question: http://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript – Austin Schmidt Aug 05 '16 at 16:03
  • 1
    However, you *can* read GET parameters using Jquery: http://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript – Austin Schmidt Aug 05 '16 at 16:03
  • So I can't get post, but I can get GET with JQuery? –  Aug 05 '16 at 16:04
  • 1
    You can read the POST with PHP(which you are already doing). You could use inline PHP if you want to output its value onto the page, like `$("[name=question_id]").val(=$question_id ?>);` – Austin Schmidt Aug 05 '16 at 16:07
  • can I define it with php for Jquery to read on that same page? -- make it an input of some sort? a hidden html input - onload? –  Aug 05 '16 at 16:08
  • how can I pass the [name=question_id] into a variable in JQuery? var questionid1 = [name=question_id].... would this be right? var questionid = (); –  Aug 05 '16 at 16:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120261/discussion-between-austin-schmidt-and-sol). – Austin Schmidt Aug 05 '16 at 16:12

2 Answers2

0

Your JavaScript, which is client-side, (JQuery is a JS library) can only parse content rendered/output by the server(PHP). One easy solution would be inline PHP like this:

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
        $("[name=question_id]").val(<?=$question_id?>);
        $('#successMessage_'+question_id).html('<p>hidden value success</p>');
    });
</script>
Austin Schmidt
  • 316
  • 1
  • 13
0

i think this code will helps you `

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
         $("[name=question_id]").val(<?php echo $question_id ?>);

        $('#successMessage_'+<?php echo $question_id ?>).html('<p>hidden value success</p>');
    });
</script>`
ubm
  • 636
  • 11
  • 21