Jump to content

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"

}

 

}

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]

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

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

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)

 

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

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.

 

 

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.