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
drop down with other option
Started 16 years ago by ptrptr | 8 posts |
-
My forms are setup as drop down choice.
I want to add "other" end of the choice so I don't have to create long drop down list.
The "other" allow user to enter desire order ## outside of the list of choice. Can this be done?
order 5
order 10
order 15
order 20
"other"Posted 16 years ago # -
I think you can put a "text box" for another order number and show when the user select "other". To do this You need to hack some code to machform files , let's say you have form id = 1 with these element :
- order choice field [ element id = 1] --> I assume "other" selection value is "2"
- text box field [element id = 2]After that you should edit "includes/view-functions.php" file, try to following these steps :
1. Go to around line 648 ~ 647, you will see these code :
$element_markup = <<<EOT <li id="li_{$element->id}" {$error_class}> <label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label> <div> <select class="element select {$element->size}" id="element_{$element->id}" name="element_{$element->id}" > {$option_markup} </select> </div>{$guidelines} {$error_message} </li> EOT;
replace with
if ($_GET['id'] == 1) { $add_event = 'onchange="javascript:showTextBox()"'; } $element_markup = <<<EOT <li id="li_{$element->id}" {$error_class}> <label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label> <div> <select class="element select {$element->size}" id="element_{$element->id}" name="element_{$element->id}" {$add_event}> {$option_markup} </select> </div>{$guidelines} {$error_message} </li> EOT;
2. Go to around line 1833 ~ 1834, you will see this
//If you would like to remove the "Powered by MachForm" link,.. $form_markup = <<<EOT
put the code above that line
if ($_GET['id'] == 1) { $add_jquery =" $(document).ready(function() { $('#li_1').hide(); }); "; }
3. And finally :) go to line 1841, you will see this
<script type="text/javascript" src="js/view.js"></script>
then add these code, bellow that line
<script type="text/javascript" src="js/jquery/jquery-core.js"></script> <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(); } } </script>
MachForm Support
Posted 16 years ago # -
I follow your instruction but It did not work.
Here is another way to look at it.
My form has more than 10 field using drop down choice. Currently All field has 6 choices.
Order 5
Order 10
Order 15
Order 20
Order 25
Order 30I want to add 7th choice to be "Other"
Order 5
Order 10
Order 15
Order 20
Order 25
Order 30
OtherWhen I choose "other", I want to have a new text field to enter any number outside of my choice in the same field.
Is your solution work as I described?
Posted 15 years ago # -
Here is demo page I am testing.
http://www.pharmedixrx.com/machform/view.php?id=4I made all the change above. It seems Java Script is not working!
Posted 15 years ago # -
Hmm it seems you've set the wrong id. In your form you have drop down id = 4 and text box id = 6, then java script code should be like this :
<script type="text/javascript"> {$add_jquery} function showTextBox() { //reset text box value $('#element_6').val(''); //show hide the field //change the value based on your "other" selection value if ($('#element_4').val() == '7') { $('#li_6').show(); } else { $('#li_6').hide(); } } </script>
and make sure you set this code :
$_GET['id'] == 1
to
$_GET['id'] == 4
MachForm Support
Posted 15 years ago # -
I'm also trying to create a field hide/show depending on a radio button (multiple choice). I will try this. Though, the question I have is this...
Does this mean that the custom application of the hide/show will carry over to every other form too because dont they all share the view-functions.php file?
Posted 15 years ago # -
I'm also on this problem.
i got it working after some trial and error.but now i wanted to have a 2nd dropdown menu with a text field apearing on 1 of the options.
Do i just need to copy paste the <script> and the documenet ready hide function?
(1 time the element markup is enough right?)Thats what i tried so far, except that i somehow cant seem to get the paragraph text boxes to be hidden from the start anymore, and i only get 1 dropdownbox working (the text box does dissapear when i select a non text box option)
any idea's?
Posted 15 years ago # -
I now use what Redityo posted.
Except like in my last post i try to get 2 of those "other" options that create a textfield.
added a $('#li_10').hide(); line to hide the 2nd line i want hidden.i basically did the same for the script. ppasted a 2nd version of the function showTextBox() with the corretc lines into the same script.
weird thing is, only the 2nd other option works.
the same happens when i create 2 seperate script codes.Posted 15 years ago #
Reply
You must log in to post.