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

Question

Question

Javascript: if condition matches, then some text with field value

asked on November 11, 2015

Hello,

I have this scenario:

There are 3 fields in play:

Field137: Type = RadioButton, depending upon the selection 2 other fields appear for text which are 138 & 187

Now, depending upon the selection of RadioButton, the text is entered & I want this value to be in another field with some other text.

I try to express in the form I think should work, but not very sure...

 

var AValue = function (){
   
    if($('#q137 select').val() == 'Anz. Arbeitstage'){
      $('#q268 input').val('in the (Field138) here');
    }

    else if($('#q137 select').val() == 'Enddatum bis'){

      $('#q268 input').val('on mark (Field187) now');
    }
  }
   $('#q214').on('blur change', AValue);

0 0

Answer

SELECTED ANSWER
replied on November 12, 2015

Thank you Sahil for attending the CFW with me today. Here is the final code that we came out with that works well for what you wanted.

 

// Concatenate values for Arbeit bis field id= 187
var Vdatum = function (){
 
  
      var datum  = $('#q187 input').val();
        $('#q268 input').val('bis zum ' + datum);
   }
    
    $('#q187').on('blur change', Vdatum);
  $('#q137 input[value="Enddatum bis"]').click(Vdatum);
  
// Concatenate values for Arbeit bis field id= 138
 
  var Vtage = function (){
    
         var tage = $('#q138 input').val();   
        $('#q268 input').val('innerhalb von ' + tage + ' Arbeitstagen');
       } 
     
   $('#q138').on('blur change', Vtage);
  $('#q137 input[value="Anz. Arbeitstage"]').click(Vage);

Let me know if you have further concerns.

0 0
replied on November 12, 2015

Thanks a lot Nathan!!!

As always, you are Awesome!

0 0

Replies

replied on November 11, 2015

Sorry, forgot to mention field types:

137 = RadioButton 

138 = Single Line

187 = Single Line

268 = Single Line

 

Thanks!

0 0
replied on November 11, 2015

Just wondering why Field Rules would not work for this scenario? If you need values inside the field, you can add it into the "default value" within the field properties.

0 0
replied on November 11, 2015

Field rules won't help.

I want the value of fields 138 & 187 to be concatenated .

Thanks!

Sahil

0 0
replied on November 11, 2015

I think I understand the question now! I recommend using the change function to accomplish what you want. Here is my example:

$(function() {
	$('#q2 input').on('change', function() {

	var radiobutton = $('#q1 input').val();
  	var singleline = $('#q2 input').val();
      	
    $("#q4 input").val(radiobutton + ' and ' + singleline);
  
	});
  
});

When Single Line 1 is changed, this will capture the value in Radio Button and Single Line 1 and then populate the values in Single Line 3:

 

Also, make sure you assign values to your radio button options:

0 0
replied on November 11, 2015

Cathy,

Thanks, but I don't want to capture the value of radio.

Let me try to explain again, based on radio Selection it will be determined which Fields value is to be captured, then based on that different fields value will be put in another field with some text, problem is value of Field will be in middle of text.

That's why I was following if condition

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

Sign in to reply to this post.