开发者

empty value of option's element

开发者 https://www.devze.com 2023-01-18 18:23 出处:网络
I have a similar problem like old problem of mine. my code: function reset_admin() { a = document.getElementById(\'event\').value;

I have a similar problem like old problem of mine.

my code:

function reset_admin()
{
    a = document.getElementById('event').value;
    t = document.getElementById('category').value;
    document.getElementById('admin').reset();
    document.getElementById('event').value = a;
    document.getElementById('category').value = t开发者_如何学Python;
}
<form id="admin" action="iframe_admin.php" onsubmit="" method="post" target="iframe_admin">
.....
<input type="button" class="filter_button" id="Clear" name="Clear" value="Clear" 
onclick="reset_admin();document.getElementById('admin').submit(); />

the function is in external js file. the propose is that after pressing on clear, the event and the category will stay the same before the clear.

In ff it's works. In IE the event and the category are empty and than the page get stacked. I tried to do:

function reset_admin()
{
    a = document.getElementById('event').options[getElementById('event').selectedIndex].value;
    t = document.getElementById('category').options[getElementById('category').selectedIndex].value;
    document.getElementById('admin').reset();
    document.getElementById('event').value = a;
    document.getElementById('category').value = t;
}

but this is not working as well.

thank you!


Store and restore the selectedIndex instead since you don't care about the actual value, like this:

function reset_admin()
{
    var a = document.getElementById('event').selectedIndex,
        t = document.getElementById('category').selectedIndex;
    document.getElementById('admin').reset();
    document.getElementById('event').selectedIndex = a;
    document.getElementById('category').selectedIndex = t;
}

I also added var to the indexes your fetching, just to about the global variables there, but that's not the important change, setting selectedIndex instead is :)

You can give it a try here.

0

精彩评论

暂无评论...
验证码 换一张
取 消