Javascript create a custom value from two other values

Hi All,

I am using the 3rd party multi cascading list and I would like to be able to take part of each selected value to create a custom text value.

For example, the selected values would be,

A. cascade select 1 | 1. cascade select 2 | a. cascade select 3

I would like to take the vales of each box, trucate, then add it to a custom field as

"A.1.a"

Any Thoughts?

thnaks

Art

4 answers

This widget could not be displayed.

can you share me the source(id's, you can check this by using firebug in firefox ) of the multi cascading field? so can able to give solution

This widget could not be displayed.

Thanks for the quick feedback Rambanam,

It looks like the following

<div class="mlcs-customfield">
<div class="hidden mlcs-child-options">selectedValues=Object { customfield_10100:0="-1", customfield_10100:1="-1", customfield_10100:2="-1", more...}
<select id="customfield_10100:0" class="select" name="customfield_10100:0">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10100" data-parent-option-id=""> 1. Selection 1 </option>
</select>
<select id="customfield_10100:1" class="select" name="customfield_10100:1">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10101" data-parent-option-id="10100"> 1. Selection 2 a </option>
<option class="mlcs-customfield-option" value="10102" data-parent-option-id="10100"> 2. Selection 2 a </option>
</select>
<select id="customfield_10100:2" class="select" name="customfield_10100:2">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10106" data-parent-option-id="10102"> 1. Selection 3 a</option>
<option class="mlcs-customfield-option" value="10107" data-parent-option-id="10102"> 2. Selection 3 b </option>
</select>
<select id="customfield_10100:3" class="select" name="customfield_10100:3">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10108" data-parent-option-id="10106"> 1. Selection 4 a </option>
<option class="mlcs-customfield-option" value="10115" data-parent-option-id="10106"> 2. Selection 4 b </option>
</select>
<select id="customfield_10100:4" class="select" name="customfield_10100:4">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10109" data-parent-option-id="10108"> 1. Selection 5 a </option>
<option class="mlcs-customfield-option" value="10110" data-parent-option-id="10108"> 2. Selection 5 b </option>
<option class="mlcs-customfield-option" value="10111" data-parent-option-id="10108"> 3. Selection 5 c </option>
</select>
<select id="customfield_10100:5" class="select" name="customfield_10100:5">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10112" data-parent-option-id="10111"> 1. Selection 6 a </option>
<option class="mlcs-customfield-option" value="10113" data-parent-option-id="10111"> 2. Selection 6 b </option>
<option class="mlcs-customfield-option" value="10114" data-parent-option-id="10111"> 3. Selection 6 c </option>
</select>
</div>

<div class="field-group">
<label for="customfield_10108">FS_Notes</label>
<textarea id="customfield_10108" class="textarea long-field" rows="5" name="customfield_10108" cols="40"></textarea>
<div class="description">Functional Spec Notes</div>
</div>

So I am trying to get customfield_10108 to be

1.2.1.1.3.1

based on the following cascadding choice

<option class="mlcs-customfield-option" value="10100" data-parent-option-id=""> 1. Selection 1 </option>
<option class="mlcs-customfield-option" value="10102" data-parent-option-id="10100"> 2. Selection 2 a </option>
<option class="mlcs-customfield-option" value="10106" data-parent-option-id="10102"> 1. Selection 3 a</option>
<option class="mlcs-customfield-option" value="10108" data-parent-option-id="10106"> 1. Selection 4 a </option>
<option class="mlcs-customfield-option" value="10111" data-parent-option-id="10108"> 3. Selection 5 c </option>
<option class="mlcs-customfield-option" value="10112" data-parent-option-id="10111"> 1. Selection 6 a </option>

Thanks again for your offer to help,

Art

This widget could not be displayed.

sample code i am giving here

<script type="text/javascript">
jQuery(document).ready(function($) {	
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {	
	getCascadingValue();
});
getCascadingValue();
function getCascadingValue(){		
		var multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:5]:checked + label').text();		
		$('#customfield_10100:0').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text();
		});
		$('#customfield_10100:1').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text();
		});
		$('#customfield_10100:2').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text();
		});
		$('#customfield_10100:3').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text();
		});
		$('#customfield_10100:4').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text();
		});
		$('#customfield_10100:5').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:5]:checked + label').text();
		});	
		
		alert("MultiSelectValue"+multiselectValue);
}
	
});
</script>

Thanks for the sample code, I will try over the weekend and revert back as soon as possible,

thanks again for the quick help.

Art

i suggest load javascript as webresource module in plugin if you want to run this on create screen

https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

This widget could not be displayed.

Thankyou for the link Rambanam, however I have struggled for two days to understand howthis works. Is there a step by step guide to getting the webresource plugin set up and then use the JS?

thanks

Art

Suggest an answer

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

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

172 views 1 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you