jholstein Posted September 27, 2007 Share Posted September 27, 2007 I am trying to modify a piece of classifieds software called BosClassifieds by taking a regular text box and altering it to use this 'Key in 10 characters' form at the top of this page. http://jennifermadden.com/javascript/stringmaxLength.html I placed the 'textarea' code within the php file and I'm trying to get it to receive its javascript action from a external javascript.js file. I'm a novice at javascript and php, so although the form appears ok and works within the page by recording the data, the 'word count' function isn't pulling its javascript action. Could someone look at the code snipets that I'm using below and see if they know what I need to change to make this work? Or..is it possible to place the neccessary javascript within the php file to acomplish this without pulling from an external javascript.js file? PHP FILE $adDef .=<<<ENDITEM <tr> <td>{$Languages['account']['adsscreendesc']}:</td><td><textarea name="newDesc" rows="4" cols="25" wrap onKeyPress="characterLimit()">$newDesc</textarea> <br> <input type="text" name="counter" size="32" value="Remaining characters: 300"><br> <br> <input type="reset" value="clear"> </td> </tr> ENDITEM; JAVASCRIPT.JS FILE function characterLimit() { var characters = document.newDescform.text.value if (characters.length <= 299) {<br> document.newDescform.counter.value = "Remaining characters: " + (299 - characters.length) } else { document.newDescform.counter.value = "Over Limit by: " + (characters.length - 299) + " characters" } } Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/ Share on other sites More sharing options...
BlueSkyIS Posted September 27, 2007 Share Posted September 27, 2007 a php file is the same as a html file except the file contains PHP code in between <? and ?> tags. so all you have to do to include your JS is put it in the PHP outside of the <? and ?> tags. Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-356439 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 Your PHP file is incorrect, but not because the php's incorrect, but your html field names aren't correct. That's why it's not working. Can you post the full code for your page? Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-356444 Share on other sites More sharing options...
jholstein Posted September 27, 2007 Author Share Posted September 27, 2007 Thanks for the help. I attached the php file and the javascript.js file (zipped together). The added code in the post.php file starts at line 370 and the corallating javascript code is at line 178 in the javascript.js file. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-356470 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 OK, try with the attached files. Regards Huggie [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-356495 Share on other sites More sharing options...
jholstein Posted September 27, 2007 Author Share Posted September 27, 2007 Still not functioning but I noticed that I had a form name in the javascript, but no form tags in the php code. I changed it to this: PHP File <tr> <td>{$Languages['account']['adsscreendesc']}:</td><td><textarea name="newDesc" rows="4" cols="25" wrap onKeyPress="characterLimit()">$newDesc</textarea> <br> <input type="text" name="counter" size="32" value="Remaining characters: 300"><br> <br> <input type="reset" value="clear"> </td> </tr> JAVASCRIPT FILE function characterLimit() { var characters = document.newDesc.value if (characters.length <= 299) {<br> document.newDesc.counter.value = "Remaining characters: " + (299 - characters.length) } else { document.newDesc.counter.value = "Over Limit by: " + (characters.length - 299) + " characters" } } .....but it still didn't work. I also tried putting a form name in the php code but it makes the submit button at the bottom of the page not function Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-356509 Share on other sites More sharing options...
HuggieBear Posted September 28, 2007 Share Posted September 28, 2007 There were form tags in the PHP code, I know, I changed them! I only added a 'name' element to the relevant form tag though, and then changed the javascript to look at that field. It all works here. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-357037 Share on other sites More sharing options...
keeve Posted September 28, 2007 Share Posted September 28, 2007 You should put a form tag in there..you reference a wrong object in the script. do something like this.. <form name=form1><tr> <td>{$Languages['account']['adsscreendesc']}:</td><td><textarea name="newDesc" rows="4" cols="25" wrap onKeyPress="characterLimit()">$newDesc</textarea> <input type="text" name="counter" size="32" value="Remaining characters: 300"> <input type="reset" value="clear"> </td> </tr> </form> in your script do this: document.form1.counter.value = "Remaining characters: " + (299 - characters.length) Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-357067 Share on other sites More sharing options...
HuggieBear Posted September 28, 2007 Share Posted September 28, 2007 You should put a form tag in there..you reference a wrong object in the script. The code already has a form tag in it. It's just not included in this snippet. Take a look at the attached files in the earlier post... Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-357073 Share on other sites More sharing options...
jholstein Posted September 28, 2007 Author Share Posted September 28, 2007 So you can see where this code is functioning: http://www.rcreader.com/index.php?option=com_wrapper&Itemid=332 you can use - user=justintest, pass=password to log into a test account, then clilck on 'post an ad', select category and ad type, then you will come to the screen that is displaying the post.php file. I took your altered post.php file and your altered javascript.js file and wrote them over the old ones, but I'm still not getting the 'character count down' that should be happening. Quote Link to comment https://forums.phpfreaks.com/topic/70906-calling-javascriptjs-file-from-a-php-file/#findComment-357151 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.