gpt4 book ai didi

javascript - 交响乐团 : Using JavaScript in a onChange-event in a form and calling an action from the JS-Function

转载 作者:行者123 更新时间:2023-11-28 13:43:12 24 4
gpt4 key购买 nike

我以前从未使用过 Javascript,但现在我在我的 Symfony 项目 (Symfony 1.4) 中需要它,并且对于在哪里添加代码以使其正常工作存在一些问题:

我在“aktionLimit”模块中有一个模板(indexSuccess),其中显示“Aktion”类的对象的变量值:

<p>Value1: <?php echo $aktion->getValue1()  ?></p>
<p>Value2: <?php echo $aktion->getValue2() ?></p>
<p>Value3: <?php echo $aktion->getValue3() ?></p>

<?php include_partial('form', array('form' => $form)) ?>

这是执行索引:

$this->aktion = AktionlimitPeer::getByName($this->getUser()->getAttribute('aktion'));

$aktionParam = new Aktion();
$aktionParam->setName($this->aktion->getName());

$this->form = new AktionlimitForm(array(), array("aktion" => $aktionParam));

AktionLimitForm 如下所示:

$aktionForm = new AktionForm($this->getOption('aktion'), array("limit" => true));

$this->embedForm('Aktion', $aktionForm);

$this->widgetSchema['neuerWert']= new sfWidgetFormInputText();

嵌入的 AktionForm 只有一个元素(一个下拉框,其中包含“Aktion”对象的唯一名称):

$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' =>   AktionPeer::getTypes()),array('onchange' => '???'));

每当用户在下拉框中选择另一个“aktion”时,我想在executeIndex中加载当前对象“aktion”(由名称引用)并在indexSuccess中显示其值(值1-3)。(提交时它会导致另一个 Action 。)

我需要一个在onChange-Event 中调用executeIndex 的函数。我可能必须在 web/js 文件夹中声明该函数,对吗?但是如何从表单中调用该函数呢?如何在 JavaScript 函数中调用操作?

我希望你能理解我所写的内容——今天我很难用英语解释这个问题:)有人可以帮忙吗?

最佳答案

首先,考虑升级到 symfony 2。

然后,如果您决定使用 jquery(不错的 JavaScript 框架),则无需在表单类型中配置它。使用jquery,您可以非常轻松地将事件绑定(bind)到元素。

$(document).ready( function() {
$('#id_of_the_form_field').change(function() {
// to get the selected value
var selected = $(this).val()

// do your magic pony stuff
});
});

要从 javascript 调用 php 操作,您需要向相关路由发出 ajax 请求。

关于javascript - 交响乐团 : Using JavaScript in a onChange-event in a form and calling an action from the JS-Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16355701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com