26 lut 2014

Zdarzenie focus i blur na polu input

$('#auto').focus(function () {
  if ($(this).val() == $(this).attr('valueDef')) {
    $(this).val('');
  }
  $(this).css({ 'color': '#000' });
});
$('#auto').blur(function () {
  if ($(this).val() == '') {
    $(this).val($(this).attr('valueDef'));
    $(this).css({ 'color': '#93999e' });
  } else {
    $(this).css({ 'color': '#000' });
  }
});
6 lis 2013

Skopiowanie wartości wybranej opcji pola select

Skopiowanie wartości wybranej opcji pola select:
- wykorzystanie selectedIndex
- wykorzystanie get(0)

$(document).ready(function () {
  $('#select_sql').change(function () {
    var idx = $(this).get(0).selectedIndex;
    var value = $(this).get(0).options[idx].value;
    $('#sql').val(value);
  });
});
6 lis 2013

Przypisanie funkcji do elementów strony

Javascript:

var form_arr = $('form[name*="paragon"]').get();
if (form_arr.length > 0) {
  for (var i = 0; i < form_arr.length; i++) {
    upload_file('_ins_' + $(form_arr[i]).attr('attr_row_id'));
  }
}

Html:

<form name="paragon_220">
  <div id="upload_ins_220"></div>
  <ul id="files_ins_220"></ul>
  <input type="submit" name="submit" value="Zapisz" />
</form>