简体   繁体   English

Javascript下拉菜单 - 更改选择时刷新

[英]Javascript Dropdown Menu - Refresh when the selection is changed

I am trying to set this up so that when a user changes the 'hier_start', the page is refreshed and the dropdown is preselected with the selection that was just made. 我试图设置它,以便当用户更改'hier_start'时,页面将刷新,并且预选下拉选项与刚刚进行的选择。

<form name='categories' id="categories">
<div class="row">
    <select name="hier_start" onchange="javascript: NextCat('A', this.value)">
    <option value="0" parent="0">Select...</option>
    [% FOREACH hier_start IN categories.keys %]
    <option value="[% hier_start %]">[% hier_start %]</option>
    [% END %]
    </select>
    <select name="hier_A" style="display:none" onchange="javascript: NextCat('B', this.value)">
    <option value="0" parent="0">Select...</option>
    </select>
    <select name="hier_B" style="display:none" onchange="javascript: NextCat('C', this.value)">
    <option value="0" parent="0">Select...</option>
    </select>
    <select name="hier_C" style="display:none" onchange="javascript: NextCat('D', this.value)">
    <option value="0" parent="0">Select...</option>
    </select>
    <select name="hier_D" style="display:none">
    <option value="0" parent="0">Select...</option>
    </select>

</div>

The onchange attribute should only contain the action to perform: onchange属性应该只包含要执行的操作:

<select name="hier_start" onchange="javascript: NextCat('A', this.value)">

should be 应该

<select name="hier_start" onchange="NextCat('A', this.value)">

I don't see any details as to your approach for refreshing the page, so I cannot provide any insight on that other than you probably don't need to refresh the page at all. 我没有看到有关刷新页面的方法的任何细节,因此除了您可能根本不需要刷新页面之外,我无法提供任何其他信息。

You need to use a server side language (PHP, ASP, etc) or cookies to send the values. 您需要使用服务器端语言(PHP,ASP等)或cookie来发送值。 There might be a way of doing it by replacing the html without refreshing the page (which I don't recommend) but this disappears when the page is reloaded again since it loads the original .html file. 可能有一种方法可以通过替换html而不刷新页面(我不建议)来实现它,但是当页面重新加载时它会消失,因为它加载了原始的.html文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM