2012-05-25 22 views
2

嗨,我使用PHP和jQuery。我有dinamically创建这样的Jquery Onclick更改隐藏参数并提交

<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> 

我javasctipt脚本是一个div的名单,我挑ID的名称点击,我隐藏的参数设置为ID的名称,我想提交表单

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

形式为:

<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> 

但在接下来的页面我没有之后的参数。

回答

0

你需要给name属性#testo,然后试试这个:

e.g

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

您的形式是<script>标签内,把它放在<script>标签之外。

和写入以下内DOM代码准备像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> 
+0

我观察到的另一个问题...我设置形式的行动,在div不同的URL的标签和浏览器重定向到a中的网址而不是表单中的网址。如果我将href设置为与它不再工作的形式相同。我试着用你的代码所有这一切。 – Simone

+0

我把脚本函数名称()(你的代码)和在href =“javascript:name()”...但现在有必要点击两次,因为拳头没有任何反应......但在双击我在下一个页面中有一个帖子参数,因为我想 – Simone

+0

@Simone为什么你的表格在'