Web Analytics Made Easy -
StatCounter hide field on click of a button - CodingForum

Announcement

Collapse
No announcement yet.

hide field on click of a button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • hide field on click of a button

    Hi,

    I want to hide a select box on click of the CLose Button.

    if(isset($_POST['Close'])){

    echo 'Test';

    $sJavaScript = "function HideFields()

    document.f1.LstSchoolName.style.visibility = 'hidden'";

    }

    This routine does get executed cos I the echo statemnt is shown except my listbox is not hiding, what am I doning wrong.

  • #2
    2 questions.

    1. Are you printing the javascript code to your page, and calling the function?

    2. Is your javascript code within <script> tags. You could try something like:

    PHP Code:
    if(isset($_POST['Close'])){

    $javascript '
    function hide_field(){

    document.f1.LstSchoolName.style.visibility = "hidden";

    }

    hide_field();
    '
    ;

    echo 
    'Test';

    echo 
    '<script type="text/javascript">';
    echo 
    $javascript;
    echo 
    '</script>';


    The code could be compacted slightly more but this may give you a better idea.

    You could also consider having php check if $_POST['close'] is set, and if it is just dont put the field in the page the first place, or making it a hidden field.

    Hope this helps
    PHP Weekly - A PHP Developers Resource
    PHP 5.1.4 and Ruby on Rails web hosting
    Moderator of PHP and Work offers and Requests
    Install Apache/PHP/MySQL
    (by marek_mar) | TinyPlugin Architecture

    Comment


    • #3
      You may also want to consider the use of DOM and Javascript entirely. Or even using CSS with "visibility: hidden".

      Good luck,
      Sadiq.

      Comment

      Working...
      X