This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

dropdown list when select hide input type text field or disable


  1. johntorre
    Member

    Is it possible to hide or disable 1 text area field when i select one of the option in my DROPDOWN LIST..

    Posted 15 years ago #
  2. redityo

    Hi,

    I think your problem similar with this post :

    http://www.appnitro.com/forums/topic/drop-down-with-other-option?replies=2#post-5552


    MachForm Support

    Posted 15 years ago #
  3. johntorre
    Member

    hi Sir Redityo... from the solution you gave.. can i ask how can i add different function showtextbox2() in the specific element?

    for example

    if ($_GET['id'] == 1) {
    $add_event = 'onchange="javascript:showTextBox()"';

    }

    i just want to add another showtextbox2()
    for specific elements only. how to write that sir..

    something like this logic sir:

    if ($element->id)== '12' {
    $add_event = 'onchange="javascript:showTextBox(2)"';
    }

    Thank you...

    Posted 15 years ago #
  4. redityo

    You need to change in java script section, for example your another text box id to be hide is "element_3" then the code should be like this:

    <script type="text/javascript">
    
    	{$add_jquery}
    
    	function showTextBox() {
    		//reset text box value
    		$('#element_1').val('');
    
    		//show hide the field
    		//change the value based on your "other" selection value
    		if ($('#element_2').val() == '2') {
    			$('#li_1').show();
    		} else  {
    			$('#li_1').hide();
    		}
    	}
    
    	function showTextBox2() {
    		//reset text box value
    		$('#element_3').val('');
    
    		//show hide the field
    		//change the value based on your "other" selection value
    		if ($('#element_2').val() == '2') {
    			$('#li_3').show();
    		} else  {
    			$('#li_3').hide();
    		}
    	}
    
    </script>

    after that you can call it like this

    if ($element->id== '12') {
    $add_event = 'onchange="javascript:showTextBox2()"';
    }

    MachForm Support

    Posted 15 years ago #
  5. johntorre
    Member

    Sir REDITYO your the best.. Thank you so much..

    Sir just to add for this topic and maybe will help this topic in future use. Heres the code for hiding and showing form field.


    <script type="text/javascript">

    function showTextBox() {

    if ($('#element_9').val() == '5') {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    $('#li_11').show();
    }
    else if ($('#element_9').val() == '6') {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    $('#li_11').show();
    }
    else if ($('#element_9').val() == '7') {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    $('#li_11').show();
    }
    else if ($('#element_9').val() == '9') {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    $('#li_20').show();
    }
    else if ($('#element_9').val() == '10') {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    $('#li_20').show();
    }

    else {
    $('#li_11').hide();
    $('#li_12').hide();
    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_20').hide();
    }

    }
    </script>

  6. BUT SIR REDITYO is there anyway to make it short and smooth...
    heres the example but got an error when combining..

    <script type="text/javascript">
    function showTextBox2() {

    if ($('#element_12').val() == '1') {
    $('#li_19').show();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_21').hide();
    $('#li_22').hide();
    }
    else if ($('#element_12').val() == 3, 4, 5, 6, 7) {
    $('#li_13').show();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_21').hide();
    $('#li_22').hide();
    }
    else {

    $('#li_13').hide();
    $('#li_14').hide();
    $('#li_15').hide();
    $('#li_16').hide();
    $('#li_17').hide();
    $('#li_18').hide();
    $('#li_19').hide();
    $('#li_21').hide();
    $('#li_22').hide();
    }

    }
    </script>

Posted 15 years ago #
  • redityo

    Hi Johntoree,

    Thank's to share .. and for make your conditional statement shorter, try to change the code from :

    else if ($('#element_12').val() == 3, 4, 5, 6, 7) {

    to

    else if ($('#element_12').val() == 3 ||
    $('#element_12').val() == 4 ||
    $('#element_12').val() == 5 ||
    $('#element_12').val() == 6 ||
    $('#element_12').val() == 7  {

    hope this help ..


    MachForm Support

    Posted 15 years ago #
  • johntorre
    Member

    THank you so much really help a lot.. by the way guys from the code given by SIR Redityo

    else if ($('#element_12').val() == 3 ||
    $('#element_12').val() == 4 ||
    $('#element_12').val() == 5 ||
    $('#element_12').val() == 6 ||
    $('#element_12').val() == 7 {

    just add ) to the last number to close it... thanks again..

    Posted 15 years ago #
  • redityo

    Ups .. I missed it :) Thank's ..


    MachForm Support

    Posted 15 years ago #
  • turkmedia
    Member

    hi
    i dont understand where i change
    i change in includes/view-functions.php by the post http://www.appnitro.com/forums/topic/drop-down-with-other-option?replies=2#post-5552
    but dont work and IE has error when i change the dropdown list and dont hide

    how can i hide a dropdown choises when i select from another dropdown like gender
    if gender = male show item 1,2,3,4
    and if gender = female show item 5,6,7,8
    in a drop down
    i want you to make a full guide to hide a dropdown and hide choices of dropdown
    i am makeing a employ form and need this

    Posted 15 years ago #

  • RSS feed for this topic

    Reply