views:

62

answers:

3

I want to change hidden input value on div click, so i do following:

$('#gallery').click(function(){
        if ($('input[name=isgallery]').attr('value') == '0') {
            $('input[name=isgallery]').attr('value', '1')
        }
        else {
            $('input[name=isgallery]').attr('value', '0')
        }
        $('#filterform').attr('action',$('#filterform').attr('act'));
        alert('ok');
        $('#filterform').submit();
    }
    );

when it equals 0 i change it to 1 and otherwise but it did not work and following code works:

$('#gallery').click(function(){
        if ($('input[name=isgallery]').attr('value') == '0') {
            $('input[name=isgallery]').attr('value', '0')
        }
        else {
            $('input[name=isgallery]').attr('value', '1')
        }
        $('#filterform').attr('action',$('#filterform').attr('act'));
        alert('ok');
        $('#filterform').submit();
    }
    );

and also, when i delete the function at all it still works and form submits

maybe i have one more handler for this div, but i can't find one

you can check it on http://www.4block.org/en/museum/posters and click "gallery view" on top-right

+1  A: 

Try using the val() function to change an input's value.

R0MANARMY
+2  A: 

This should work a little better cross-browser, plus less DOM traversing to find elements :)

$('#gallery').click(function(){
  $('input[name=isgallery]').each(function() {
    $(this).val($(this).val() == '0' ? '1' : '0');
  });
  $('#filterform').attr('action',$('#filterform').attr('act')).submit();
});
Nick Craver
A: 

all ok, i found this script, i only not updated it on server thanks for answers

llamerr