You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Targeting a Dropdown Field Value for Use in Clickable Link

posted on April 17, 2023

I have a form that uses JavaScript to open another form when a specific field is clicked by the user.  The new form should load based on the value of a specified dropdown field.  I have used this before, but it was for a table filled with lookup rules, and the specified field in that case was a multi-line field which I targeted using 'text area'.  I am targeting my dropdown field using 'selected' which seems right, but I can't get it to work.  The new form opens, but displays "null" where it should display the asset name which would then populate the rest of the form based on the lookup rules.  I'm sure it is a simple fix, but I can't figure it out.  Any help would be appreciated!

01$(document).on("onloadlookupfinished", function (event) {
02    $('.assetlink').click(function() {
03      t = $(this).find('.assetname selected').val();
04      console.log(t);
05       
07       
08       
09      window.open(url,'_blank');
10    });
11 
12    console.log('lookup complete');
13     
14  });

I do have other scripting activities going on, but this is the snippet related directly to opening the second form.

0 0
replied on April 17, 2023

You may need the semicolon in front of selected, so: 

1t = $(this).find('.assetname :selected').val();

 

ref: https://api.jquery.com/selected-selector/

0 0
replied on April 17, 2023

Unfortunately, that is still returning a null.

0 0
replied on April 17, 2023

It's not quite your same form, but hopefully the structure can help you out here.



If you do think your code is correct comparing it to mine, please also console log $(this) and $(this).find('.assetname') and confirm those are finding the elements you are expecting.

0 0
replied on April 17, 2023

Apparently I did not need  the (this).find portion of the code.  Maybe because this isn't a table in the form, just a single dropdown field?  Anyway, the following code appears to work properly:  

01$(document).on("onloadlookupfinished", function (event) {
02    $('.assetlink').click(function() {
03      t = $('.assetname :selected').val();
04      console.log(t);
05       
07       
08       
09      window.open(url,'_blank');
10    });
11 
12    console.log('lookup complete');
13     
14  });

 

1 0
replied on April 17, 2023

I'm glad you found the issue!

$(this) in that context should have been the document jquery object but obviously something else was going on. When debugging dont be afraid to log more than one variable, sometimes its preceding functions/variables that aren't doing what is expected.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.