2

Hi i'm using php and jquery. I have create dinamically a list of a div like that

<div class="divclass" id="<?php echo $i-1;?>">  
    <a href=" <?php echo $this->url(array('controller'=>'controller name','action'=>'action name'));?>">
    <span>Date: </span>
    </a>
</div>

My javasctipt script is, i pick the name of the id clicked, i set the hidden parameter to the name of the id and i want to submit the form

<script type="text/javascript">
    $(document).ready(function() {
        $('.divclass').click(function(){
            var idarray = $(this).attr("id");   
            document.getElementById('testo').value=idarray;
            document.forms["prova"].submit();
        });
    });

The form is:

<form id="prova"  method="post"  action="<?php echo Zend_Controller_Front::getInstance()->getBaseUrl().'/controller-name/action-name';?>">
<input type="hidden" value="" id="testo">
</form>
</script>

But in the next page i don't have the post parameter.

Simone
  • 85
  • 1
  • 9

1 Answers1

0

You need to give name attribute to #testo and then try this:

e.g

<input type="hidden" value="" id="testo" name="testo">

Your form is within <script> tag, Place it outside of <script> tag.

and write following code within DOM ready like follwing:

  <script type="text/javascript">

    $(function() {
        // after DOM ready
         $('.divclass').click(function(){
              var idarray = $(this).attr("id"); // or this.id do the same thing  
              $('#testo').val(idarray); // set value to testo
              $("form#prova").submit(); // submit the form
          });
    });
 </script>
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
  • I observed another problem...i set the action of the form to a different url of the tag a in the div and the browser redirect to the url in the a and not in the form. if i set the href the same of the form it not works again. i tried with your code all of this. – Simone May 25 '12 at 17:30
  • i put the script function name(){ your-code } and in the href="javascript:name()"...but now it is necessary to click two times because the fist one nothing happens...but after the double click i have a post parameter in the next page as i want – Simone May 25 '12 at 17:42
  • @Simone why you form is within ` – thecodeparadox May 25 '12 at 17:50
  • i make a mistake posting my code...the is to close the the javascript. the form is after that. – Simone May 25 '12 at 18:12