rodb Posted November 14, 2015 Share Posted November 14, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/299478-help-with-calling-function-in-javascript-lib/ Share on other sites More sharing options...
hansford Posted November 14, 2015 Share Posted November 14, 2015 PHP and JavaScript don't mix like that. You have PHP tags inside a JavaScript file. JavaScript has no idea what the hell that is and visa-versa. Explain what you are trying to do and we can help. Quote Link to comment https://forums.phpfreaks.com/topic/299478-help-with-calling-function-in-javascript-lib/#findComment-1526406 Share on other sites More sharing options...
rodb Posted November 14, 2015 Author Share Posted November 14, 2015 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 fieldfunction 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 Quote Link to comment https://forums.phpfreaks.com/topic/299478-help-with-calling-function-in-javascript-lib/#findComment-1526416 Share on other sites More sharing options...
Solution rodb Posted November 15, 2015 Author Solution Share Posted November 15, 2015 Thanks everyone, I found the problem. Typo in first line of comments of js file, missing '/'; Quote Link to comment https://forums.phpfreaks.com/topic/299478-help-with-calling-function-in-javascript-lib/#findComment-1526421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.