It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to set value for textbox using javascript?

Hi,

I currently need to get a copy of selected text in a select list and copy it to a defined textbox. My current code is

<script type="text/javascript">

siteCopy = document.getElementById("customerfield_10200");

site = document.getElementById("customfield_10102");

site.onchange= function()

{

siteCopy.text=site.options[site.selectedIndex].text;

}

</script>

and it seemd doesn't work. Please be advised that siteCopy is a textbox custom field and site is a select list custom field.

Thanks.

4 answers

1 vote
HeyJoe Atlassian Team Mar 20, 2012

How are you getting this JavaScript loaded into the page? You probably need to wire it up so that the javascript only executes after the page has finished loading.

You can also use jQuery in JIRA to make selecting DOM elements a bit nicer.

Try something like this:

&lt;script type="text/javascript&gt;
AJS.toInit(function() {
  var siteCopy = AJS.$("#customfield_10200");
  var site = AJS.$("#customfield_10102");

  site.change(function() {
    siteCopy.val(site.val());
  });
});


&lt;/script&gt;

Hi Joseph,

This one doesn't work for me, is there any other way which doesn't require AJS?

Thanks,

to be honest, I think this line has problem

siteCopy.val(site.val());

once I use it, I lose control to custom field, cannot add any other fields or delete any, I had to log into database and delete it manually.

1 vote
Daz Atlassian Team Apr 16, 2013

The <textarea> element, as with most HTML form inupt elements, uses the `value` attribute to get and set its text. So you can change your code to this:

var siteCopy = document.getElementById("customerfield_10200");
var site = document.getElementById("customfield_10102");

site.onchange = function() {
  siteCopy.value=site.options[site.selectedIndex].value;
}

and it should do what you want.

&lt;script type="text/javascript"&gt;
var siteCopy = document.getElementById("customerfield_10200");
var site = document.getElementById("customfield_10102");
site.onchange= function(){
    siteCopy.value=site.options[site.selectedIndex].text;
or
$("customerfield_10200").val(site.options[site.selectedIndex].text);
}
&lt;/script&gt;

i hope it should work if it is not let me know which version of jira using

Cheers,

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

303 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you