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

Question

Question

Javascript - Getting the value of a list field in forms

asked on April 25, 2017 Show version history

The only different between a list field and a single line seems to be that it is a select instead of an input. So it seems logical that I could just change the syntax to

$('.myclass select').val();

instead of "input". But NO says javascript, as usual nothing is that simple.

So I have been re-reading all the getting started with javascript and forms articles plus searching javascript development forms for how to work with the values of a "select" field by class.

Everyone appears to be using the field ID in all of their examples. This is archaic, I need to use CSS when working with fields so that I can work inside of tables and other collections.

0 0

Replies

replied on April 25, 2017

Found it works to just swap input for select when using the $(this).find method which is what I need to use anyways so that worked out perfect. Not sure why I couldn't swap it out when calling the value directly as a test.

 

$(this).find(".myclass select").val()

 

0 0
replied on April 25, 2017

Your original code works perfectly fine for stand-alone dropdown fields. See below:

$(document).ready(function() {
  console.log($('.someclass select').val());
});

Result:

But if you are, say, iterating through the rows of a table and getting the values of that dropdown field for each row, then you can use:

$(document).ready(function() {
  $('#q4 tbody tr').each(function() {
    console.log($(this).find('.someclass select').val());
  });
});

In that case, the "this" refers to the "tr" element that is currently being iterated through. It finds the ".someclass select" inside that tr (using the find() function) and prints its value.

0 0
replied on April 25, 2017

What version of Forms are you running?  There were some issues with classes in CSS and Javascript in 10.2, so you may need to apply this hotfix: https://support.laserfiche.com/kb/1013834/list-of-changes-for-laserfiche-forms-10-2-update-1-

0 0
replied on April 25, 2017

Interesting, as soon as I switched the word "input" for the word "select" the javascript went quiet. Meaning no functions ran at all, the usual case when it is unhappy with my code. 

I think that is my #1 issue as I am working with javascript more. Why does it always go quiet if it doesn't like something instead of informing me.

All other languages at least give you a line number when something is wrong with your syntax, even writing vbscript or PHP in notepad tells you when you mess up and what line number. Can I enable this with the javascript editor?

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

Sign in to reply to this post.