none
Fill item value with Client Script RRS feed

  • Question

  • Hi, can I fill a fields value according to other fields value?

    Ex: I have a field Codification 1 and Codification 2. If Codification 1 value is "G11" and Codification 2 is "I" code will be filled with "1000", if Codification 1 is "T3" and Codification 2 is "A" code will be "2000"

    thanks

    Monday, March 13, 2017 5:00 PM

Answers

  • Try this:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("select[title='Codification 2']").on('change', function() {
    		var codification1 = $("select[title='Codification 1'] option:selected").text();
    		var codification2 = $("select[title='Codification 2'] option:selected").text();
    		
    		if(codification1 == "G11" && codification2 == "I") {
    			$("input[title='Code']").val("1000");
    		}
    		if(codification1 == "T3" && codification2 == "A") {
    			$("input[title='Code']").val("2000");
    		}
        });  
    });
    </script>


    Avijit Sur

    • Marked as answer by renatois Monday, March 20, 2017 10:03 AM
    Thursday, March 16, 2017 4:08 PM

All replies

  • Try this code:

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
    		var codification1 = $("select[title='Codification 1'] option:selected").text();
    		var codification2 = $("select[title='Codification 2'] option:selected").text();
    		
    		if(codification1 == "G11" && codification2 == "I") {
    			$("input[title='Code']").val("1000");
    		}
    		if(codification1 == "T3" && codification2 == "A") {
    			$("input[title='Code']").val("2000");
    		}
        });       
    </script>


    Avijit Sur

    Monday, March 13, 2017 5:32 PM
  • Hi Avijit Sur,

    the event should be triggered when codification2 is changed instead of $(document).ready. 

    I tried that but it didnt trigger, wrong syntax?

    $("select[title='Codification 2']").onchange(function () {...

    Thanks

    Tuesday, March 14, 2017 2:57 PM
  • Try this:

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $("select[title='Codification 2']").on('change', function() {
    		var codification1 = $("select[title='Codification 1'] option:selected").text();
    		var codification2 = $("select[title='Codification 2'] option:selected").text();
    		
    		if(codification1 == "G11" && codification2 == "I") {
    			$("input[title='Code']").val("1000");
    		}
    		if(codification1 == "T3" && codification2 == "A") {
    			$("input[title='Code']").val("2000");
    		}
        });       
    </script>


    Avijit Sur

    Tuesday, March 14, 2017 4:56 PM
  • Hi Avijit, it doens't call the function when I change the dropdown value. I made a breakpoint in the code, also alerts and it's weird because I also saw that as a solution but nothing happens, the function is not even called.

    But I see the dropdown when I type it in the Explorer F12 Console

    thanks


    • Edited by renatois Thursday, March 16, 2017 3:13 PM
    Thursday, March 16, 2017 3:07 PM
  • Try this:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("select[title='Codification 2']").on('change', function() {
    		var codification1 = $("select[title='Codification 1'] option:selected").text();
    		var codification2 = $("select[title='Codification 2'] option:selected").text();
    		
    		if(codification1 == "G11" && codification2 == "I") {
    			$("input[title='Code']").val("1000");
    		}
    		if(codification1 == "T3" && codification2 == "A") {
    			$("input[title='Code']").val("2000");
    		}
        });  
    });
    </script>


    Avijit Sur

    • Marked as answer by renatois Monday, March 20, 2017 10:03 AM
    Thursday, March 16, 2017 4:08 PM