Jump to content
New Reality: Ads For Members ×

Help with calling function in javascript lib


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

 

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

Archived

This topic is now archived and is closed to further replies.



×
×
  • 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.