This topic is locked

add form field depending from another

4/28/2010 7:45:47 AM
PHPRunner General questions
ffrinai author

Hi,

I'm a novice in PHP.

I have PHPRunner 5.2.

the problem:

I have 3 fields: f1,f2,f3 in add page I want f2 or f3 depending from the value of f1 ex. I want to see and input value for field f2 if f1='1' and want see f2 if f1="2". The same problem in edit form.

Thanks and sorry for my english.

Fabio

J
Jane 4/30/2010

Hi,
use custom JavaScript code (Add page: JavaScript Onload Event on the Events tab) to show/hide fields on the fly based on value selected in another field.

Here is a sample:

document.forms.editform1.value_FieldName_1.onchange=function()

{

if (document.forms.editform1.value_FieldName_1.value==1)

{

document.getElementById("hidediv1").style.display="none";

document.getElementById("hidediv2").style.display="inline";

}

else

{

document.getElementById("hidediv1").style.display="inline";

document.getElementById("hidediv2").style.display="none";

}

}


Then edit HTML code for this page on the Visual Editor tab in HTML mode. Check my changes in bold:

{BEGIN FieldName1_fieldblock}

<TR id=hidediv1 style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; PADDING-TOP: 3px">

<TD class=editshade_b style="PADDING-LEFT: 15px" width=150>{$label TableName FieldName1}</TD>

<TD class=editshade_lb style="PADDING-LEFT: 10px" width=250>{$FieldName1_editcontrol}

</TD></TR>

{END FieldName1_fieldblock}

{BEGIN FieldName2_fieldblock}

<TR id=hidediv2 style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; PADDING-TOP: 3px">

<TD class=editshade_b style="PADDING-LEFT: 15px" width=150>{$label TableName FieldName2}</TD>

<TD class=editshade_lb style="PADDING-LEFT: 10px" width=250>{$FieldName2_editcontrol}

</TD></TR>

{END FieldName2_fieldblock}

ffrinai author 5/4/2010



Hi,
use custom JavaScript code (Add page: JavaScript Onload Event on the Events tab) to show/hide fields on the fly based on value selected in another field.

Here is a sample:

document.forms.editform1.value_FieldName_1.onchange=function()

{

if (document.forms.editform1.value_FieldName_1.value==1)

{

document.getElementById("hidediv1").style.display="none";

document.getElementById("hidediv2").style.display="inline";

}

else

{

document.getElementById("hidediv1").style.display="inline";

document.getElementById("hidediv2").style.display="none";

}

}


Then edit HTML code for this page on the Visual Editor tab in HTML mode. Check my changes in bold:


It works fine, thanks.
If possible I want to see the other field but not in input?

ex. if field1=1 i want to see field1 and field2 but input only for field1

or if field1=2 i want to see field1 and field2 but input only for field2?

Thanks.

J
Jane 5/4/2010

Hi,
here is a sample code how to disable/enable fields on the add/edit pages:

http://www.asprunner.com/forums/topic/6504-how-to-disableenable-controls-on-editadd-pages/

F
FunkDaddy 5/6/2010

I used this code and it does hide/show the row, except that when it shows the row (with the control & label I need) it displays it in very strangely... it squeezes both columns (label and edit control) into a single column under the label column of the control above it. Here is the screenshot I took (look at the "Attachment Type" field):


As you can see when showing the control something is clearly not right. Upon inspecting the darker cell to the right of "Attachment Type" with Firefox Firebug I found out its not even a cell... when I inspect that element it selects the entire table. I have fiddled with this at length and can't fix it.... I am sure its something minor. Any help would be much appreciated!
Cheers,
M

Sergey Kornilov admin 5/6/2010

I would recommend to check if table structure is not broken. You can do this in Visual Editor in HTML mode.
That table row needs to have exactly two cells defined i.e. <tr><td>...</td><td>...</td></tr>
If this doesn't help post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

F
FunkDaddy 5/7/2010

I figured out the problem (sorry, but I already uploaded and opened a support ticket as instructed by Sergey)... After inspecting the <TR> element that I was hoping to show/hide on demand (based on a value selected in a dropdown control above it)I simply changed the javascript code where it read:
document.getElementById("hidediv1").style.display="inline";
and changed it to:
document.getElementById("hidediv1").style.display="";
This fixed the problem, so now my row isn't squeezing 2 columns under the 1st column for that specific row (as shown in the screenshot I posted in this thread).
If anyone advises against the code change I made in javascript please let me know... I feel like this is a hacky solution, but it works.
M

A
ann 5/12/2010

Hi,
To fix it use

document.getElementById("hidediv1").style.display="table-row";


instead of

document.getElementById("hidediv1").style.display="";
F
FunkDaddy 5/12/2010

Thanks Ann... I'll give your solution a try. Mine worked as well, but your code looks cleaner to me.
Best,
M