In issue edit screen, unable to get updated value of customfield using javascript.

dhaval soni
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

Hi,

I have added below javascript on textbox custom field's description.

setInterval(function(){console.log('value is:'+AJS.$("#customfield_11426\\:input1").val());  //unable to get updated value on each interval tick, it just prints initial value which is found while loading edit issue screen.
},2000);

It executes on 2 sec but it just print same value of input1 textbox instead of updated values.

(just take the value which is found while loading issue edit screen but unable to get updated textbox values).

i need these updated value for further calculation.

Can you tell me what can be the cause and how to resolve .

Thank You

3 answers

1 vote
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013
try with 		
$('#customfield_11426').change(function() {  
  var val = $('#customfield_11426').val();
 
});

or 

$("#customfield_11426").keyup(function(){
   AJS.$(this).val()
  });

0 votes
Nitram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

Hi @dhaval soni ,

Change event will work correctly, where keypress, keydown,keyup are all keyboard events which will have some syncing issues, whatever you have discussed earlier is an keyboard value syncing issue,blur can also be used but when the field loses it's focus only - blur event will be called, Change is the correct event, whenever a value changes, this event will be called.So, Change event will work correctly for you.

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

your code will execute on page load, to get latest value of the field you have to place your code inside some event

something like follows

$('#customfield_11426').bind('keypress', function (e) {
  //add your code here      
});

dhaval soni
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

I have replaced and how it works -

when update the textbox valut to '157' then console.log prints '15' for AJS.$(this).val() and not 7. when give value - 1578 then shows 157. so, last char not cosndering and also, when do backspace to remove char then also it does not update value. any other event have to cosnider..?

also, when i show in "firebug" then it inspect the value as same value which is on loading the screen and no updated value.

Suggest an answer

Log in or Sign up to answer