Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By nadobii
#826035
Hi,
I write a javascript code in order to make dependent fields in dynaform. but there is a mistake. at the first time, when the user select "No" the "Reasons for disagreement" appears and it's ok.
but when the user select "Yes" and after that (before submit) select "No" the "Reasons for disagreement" and "description" appear!! while the "description" is related to "Yes" selection. json file is attached.
(6.03 KiB) Downloaded 234 times
this is javascript code:
Code: Select all
$("#action_not_approve_description").hide(); //Hide when the form loads
$("#action_teams").hide();
$("#action_plan_draft").hide();
$("#action_approve_description").hide();

$("#action_approve").setOnchange( function(newVal, oldVal) {
   $("#action_not_approve_description").hide();
  $("#action_teams").hide();
  $("action_approve_description").hide();
  $("#action_plan_draft").hide();
        
    
  if (newVal == "1") { 
    $("#action_teams").show();
    $("#action_approve_description").show();
    $("#action_plan_draft").show();
  }

  if (newVal == "0") { 
     $("#action_not_approve_description").show();
         
  }

});
thanks.
By Bosatzu
#826050
Hello!

I don't understand what you want to do......but maybe this code help you (i hope).
Code: Select all
load();

function load(){
    
   	$("#action_not_approve_description").hide();
	$("#action_teams").hide();
	$("#action_plan_draft").hide();
	$("#action_approve_description").hide();
	$("#action_approve").setOnchange(hide_show);
}

function hide_show(){

  	if ($("#action_approve").getValue() == "1") {
      	
  	    $("#action_not_approve_description").hide();
      	    $("#action_teams").show();
	    $("#action_approve_description").show();
	    $("#action_plan_draft").show();
    }
    else{
      	
    	    $("#action_teams").hide();
	    $("#action_approve_description").hide();
	    $("#action_plan_draft").hide();
      	    $("#action_not_approve_description").show();
    }
}
By nadobii
#826059
Thanks a lot :)
the first reply is ok.

my problem was as bellow:
the "description" should be appear when the "yes" is selected, but it appears next to the "Reasons for disagreement" when the "No" is selected.
7.png
7.png (66.71 KiB) Viewed 2845 times
User avatar
By amosbatto
#826069
You shouldn't be using a boolean variable for the radio button. You should use a string variable, because you have 3 states: not set, Yes and No. Also, you need to consider that the user might redisplay the form after having already filled out the form.

You should make your form something like this:
(3.69 KiB) Downloaded 241 times
The code is:
Code: Select all
function showOrHideFromAction(decision, oldVal) {    
  if (decision == "yes") { 
    $("#description").show();
    $("#action_not_approve_description").hide();
  }
  else if (decision == "no") {
    $("#description").hide();
    $("#action_not_approve_description").show();
  }
  else { //if decision == ""
    $("#description").hide();
    $("#action_not_approve_description").hide();
  }
}

//when radio button changes:
$("#action_approved").setOnchange( showOrHideFromAction );

//execute when form loads:
showOrHideFromAction($("#action_approved").getValue(), '');

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]