Jump to content

Help with calling function in javascript lib


rodb
Go to solution Solved by rodb,

Recommended Posts

I am new at using javascript files.  Currently I am trying to test a concept but can not seem to get the system to call the jscript functions.  Attached is the main PHP file (Test Hide/Show Fields) and the js file (showhide.js).  If I embed the js file in the main php things appear to work but when separate they don't.  The extension of js file has been changed to txt to allow upload.

 

TestHideShow.php

 

showhide.txt

 

any suggestions would be greatly appreciated.

Rod

 

Link to comment
Share on other sites

I am trying to hide and show fields based on the value of the "age" field.  The idea is when the user selects an age of less than 13 then the "parentPermission" fields will display and will hide if age is 13 or above.  I just noticed that I attached the wrong "showhide" file.  The correct one is listed here.

===================================

**
* File: js/showhide.js
* Author: design1online.com, LLC
* Purpose: toggle the visibility of fields depending on the value of another field
**/
$(document).ready(function() {
    toggleFields(); //call this first so we start out with the correct visibility depending on the selected form values
   //this will call our toggleFields function every time the selection value of our underAge field changes
    $("#age").change(function() { toggleFields(); });

});
//this toggles the visibility of our parent permission fields depending on the current selected value of the underAge field
function toggleFields() {
    if ($("#age").val() < 13)
        $("#parentPermission").show();
    else
        $("#parentPermission").hide();
}
=====================================

 

I am trying this code as a test for experimenting prior to trying the same approach in my main application.  The main app will not use age put using an "id" field to determine what additional information is needed from the user.  Thought it would be better to put js script in separate files that would be included in the header or footer php files.

 

Rod

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.