Jump to content

Calling javascript.js file from a php file


jholstein

Recommended Posts

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"

}

 

}

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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.

 

 

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.