This topic is locked
[SOLVED]

 How to control section (expand and collapse)

10/6/2011 10:30:30 PM
PHPRunner General questions
A
acpan author

Hi,
I read there is a way to use javascript to make foldable section expands or collapses programmatically.
Now, i need to do it based on a http posted values.
Eg. if my add form is: abc_add.php
then i have a link abc_add.php?section1expand=1
So when click and brought to the add form, the foldable section 1 should be expanded since posted values section1expand = 1
any idea vhow to do it?
thanks!

acp

A
acpan author 10/6/2011

I tried this:
In before display event of abc_add.php, i put this codes:
if ($_REQUEST["section1expand"] == 1 )

{

echo "<script language=\"JavaScript\">

$(\"#Section_section1\").show();

$(\"#Section_section1\"+\"Butt\").attr(\"src\", 'include/img/minus.gif');

</script>

";

}
It does not work.
Any idea?
thanks

acp

A
acpan author 10/8/2011

Thanks Cristian, you are most helpful. I had actually read that earlier.

It did not work on php6 rc1 but now worked with rc2.
Here's how i did it:
In before process event of contact_add.php, add this :
// initialise the variables first

echo "<script>

window.expand_section1 =0;

window.expand_section2 =0;

</script>";
// Below when receive htp://..../contact_add.php?expand1=1, it will set the javascript varaibles expand_section1 to 1
if (isset($_REQUEST["expand1"]))

{

echo "<script>

window.expand_section1 =1;

</script>";

}
// in javascript onload event
if (expand_section1 == 1 )

{

$("#section_Section1_s_1").show();

$("#section_Section1_s_1"+"Butt").attr("src", 'images/minus.gif');
$("#section_Section1_s_2").hide();

$("#section_Section1_s_2"+"Butt").attr("src", 'images/plus.gif');

}
// How to use it?

Let say in another list table say, contact_list.php:
Table List:

id, gender, add_link

// add_link is a http link that jump to contact_add.php
if gender is female: set the link to: contact_add.php?expand1=1

if gender is male: set the link to: contact_add.php?expand2=1
So if the contact is a female, then we can add details with section 1 expand while section 2 is collapsed.
I will add it to the tips section.
Thanks

acp

A
adelaide887 10/8/2011






echo "<script language=\"Javascript\">

$(\"#Section_section1\").show();

$(\"#Section_section1\"+\"Butt\").attr(\"src\", 'include/img/minus.gif');

</script>



you get one error here.... it must be this



echo "<script language=\"Javascript\">

$(\"#Section_section1\").show();

$(\"#Section_section1\"+\"Butt\").attr(\"src\", 'include/img/minus.gif');

echo "</script>"