Appnitro Software Forums » MachForm

checkbox to open a second address field

(17 posts)

  1. Freddy
    Member

    I need some help.

    On my form i have the address field called Return address.
    I would like to have a checkbox saying¨Use alternative address for pickup of goods.

    When they check the checkbox a brand new address field should just slide or popup side by side with the other one so that the customr could fill in a second address.

    How would i go to achieve this?

    I'm a beginner with PHP and the reason i bought Machform was because it´s so simple :)
    but can be a quite difficult if you want to add extra stuff.

    Hope anyone can help me :)

    Posted 3 years ago #
  2. Ok first you'll need to add a single checkbox and the address field which you would like to hide/show.

    After adding them, view the HTML source of your form and get the id for those fields.
    Let say you have the following:

    checkbox --> id = element_3_1
    address --> id = li_2

    Edit your includes/view-functions.php file, around line 1831 you should see this:

    <script type="text/javascript" src="js/view.js"></script>

    right below that line, add this code:

    <script type="text/javascript" src="js/jquery/jquery-core.js"></script>
    <script>
    	$(document).ready(function(){
    			$('#li_2').css('display','none');
    			$('#element_3_1').click(function(){
    				$('#li_2').toggle();
    			});
    	});
    </script>

    that would toggle your address field based on the checkbox.

    Make sure to adjust the above code with your own ids.

    Posted 3 years ago #
  3. Freddy
    Member

    That worked great man! I thought i wouldn´t get a reply because of being an hard request :)

    Thank you for your brilliant script and amazing support.

    Posted 3 years ago #
  4. Jacy1001
    Member

    I've tried this option and it works great.
    Now my question is:
    Is it possible to hide and reveal more lines.
    I've got element_32_1 (the ceckbox)
    and the lines li_27, li_28, li_29 to hide.
    How would the code look like

    thanks in advance

    Posted 2 years ago #
  5. Yes it's possible, try with this code :

    <script>
    	$(document).ready(function(){
    			$('#li_27').css('display','none');
    			$('#li_28').css('display','none');
    			$('#li_29').css('display','none');
    			$('#element_32_1').click(function(){
    				$('#li_27').toggle();
    				$('#li_28').toggle();
    				$('#li_29').toggle();
    			});
    	});
    </script>
    Posted 2 years ago #
  6. I would like to do something very similar, but opposite, meaning --> based on a checkbox I want hide fields rather than have then show. Is this possible? For example, I have a form and they can check the box "reschedule" -- when they check it I want some elements to hide.

    Thanks.

    Posted 2 years ago #
  7. Scratch the above question - that is what Redityo answered. However, I have another question, how do you make the above javascript pertain to one form and not all?
    Thanks!

    Posted 2 years ago #
  8. You can remove these line to make the field displayed when the form loaded

    $('#li_27').css('display','none');
    	$('#li_28').css('display','none');
    	$('#li_29').css('display','none');

    And to use the script on specific form, you can use the method in here :

    http://www.appnitro.com/forums/topic/showhide-question?replies=2

    Posted 2 years ago #
  9. This method seems to work well with the standard iframe methodology, but doesn't work with the advanced code option.

    Is there a solution that works for the advanced code?

    Thank you.

    Posted 1 year ago #
  10. Just a thought - would it be possible to put a similar script in the head of the webpage, so as the php delivery method works?

    Posted 1 year ago #
  11. To apply the code using the advanced code, you need to modify another line.
    Edit your "includes/view-functions.php" file and search around line 2171.

    Add the same code as above.

    Or yes, you can also put the script into the head of the webpage.

    Posted 1 year ago #
  12. Tried the head of the webpage and that works great. Thank you!

    Posted 1 year ago #
  13. anderfelix
    Member

    Hi there … it all works great.
    But is it possible to show/hide a field that is required?

    If i do it the way you show, i cant send the form if the adressfield is hidden (set to display:none)

    But in my case i need the adressfield to be required if shown. is it possible?

    Posted 1 year ago #
  14. I'm looking to make a field mandatory based on a check box selection. I have 3 check boxes
    and if any one of them is clicked I'd like to make the phone number field mandatory.

    http://www.home-search-the-easy-way.ca/view.php?id=3

    Posted 10 months ago #
  15. I'm afraid setting the "required" rule for a field based on a checkbox won't be quite easy to do, since this would involve server side interaction, not just a simple javascript.

    Basically, you will need to do some ajax call when the checkbox being selected and the ajax need to modify the "required" value of the field.

    We won't be able to provide you with the code for this. Sorry.

    Posted 10 months ago #
  16. Ok thanks for the speedy reply.

    Posted 10 months ago #
  17. jpello
    Member

    Can this same code be used to add a field if a dropdown selection is selected?

    I.E.

    Do you play Golf?

    If Yes, show a text box where they put their handicap

    If No, do nothing

    Posted 5 days ago #

RSS feed for this topic

Reply

You must log in to post.