473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Javascript function throwing error

I've been banging my head on my keyboard over this for a few days now, and hoping someone out there can help me out. I'm not very expirienced in Javascript, but undestand the basics. What I have is a textarea in a form, that I want to test and give a warning if more than a set number of characters.

Expand|Select|Wrap|Line Numbers
  1. 1. <script language="JavaScript" type="text/javascript">
  2. 2. <!--
  3. 3. function Test_Too_Long(element, maxChar)
  4. 4.    if (parseInt(element.value.length)>maxChar)
  5. 5.    {
  6. 6.        msg = "You have entered " + element.value.length + " characters.\n\n"
  7. 7.        msg = msg + "Please try to limit your post to less\nthan "+maxChar+" characters otherwise this\ncauses the page to run on.\n"
  8. 8.        alert(msg);
  9. 9.    }
  10. 10.-->
  11. 11.</script>
  12. 12.
  13. 13<form name="TradeBoardUpdate" method="post" action="trade_board_update.asp?v=<%=request("v")%>&post=true" >
  14. 14.<table border="0" id="overall" align="center" cellspacing="3">
  15. 15.<tr>
  16. 16.    <th>Asking for in return<br>
  17. 17.    <textarea name="return" id="return" cols="28" rows="8" onChange="Test_Too_Long(this, 250)"><%=objRec1("asking")%></textarea></th>
  18. 18.<tr>
  19. 19.    <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit">
  20. 20.<input type="reset" name="reset" value="Reset"></td>
  21. 21.</tr>
  22. 22.</table>
  23. 23.</form>
So as it stands like this if I comment out line 4. the function works as it's designed (minus this line). When I uncomment out that line, once the focus leaves the text area, it throws a javascript error "object expected" for line 17.

Can you see something I should try?? Any assistance is greatly appreciated.
Oct 28 '06 #1
1 1128
RamananKalirajan
608 512MB
I've been banging my head on my keyboard over this for a few days now, and hoping someone out there can help me out. I'm not very expirienced in Javascript, but undestand the basics. What I have is a textarea in a form, that I want to test and give a warning if more than a set number of characters.

Expand|Select|Wrap|Line Numbers
  1. 1. <script language="JavaScript" type="text/javascript">
  2. 2. <!--
  3. 3. function Test_Too_Long(element, maxChar)
  4. 4.    if (parseInt(element.value.length)>maxChar)
  5. 5.    {
  6. 6.        msg = "You have entered " + element.value.length + " characters.\n\n"
  7. 7.        msg = msg + "Please try to limit your post to less\nthan "+maxChar+" characters otherwise this\ncauses the page to run on.\n"
  8. 8.        alert(msg);
  9. 9.    }
  10. 10.-->
  11. 11.</script>
  12. 12.
  13. 13<form name="TradeBoardUpdate" method="post" action="trade_board_update.asp?v=<%=request("v")%>&post=true" >
  14. 14.<table border="0" id="overall" align="center" cellspacing="3">
  15. 15.<tr>
  16. 16.    <th>Asking for in return<br>
  17. 17.    <textarea name="return" id="return" cols="28" rows="8" onChange="Test_Too_Long(this, 250)"><%=objRec1("asking")%></textarea></th>
  18. 18.<tr>
  19. 19.    <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit">
  20. 20.<input type="reset" name="reset" value="Reset"></td>
  21. 21.</tr>
  22. 22.</table>
  23. 23.</form>
So as it stands like this if I comment out line 4. the function works as it's designed (minus this line). When I uncomment out that line, once the focus leaves the text area, it throws a javascript error "object expected" for line 17.

Can you see something I should try?? Any assistance is greatly appreciated.


Hello Friend your code is good and working fine but needs a simple modification while checking in the If Condition please replace the maxChar by parseInt(maxChar). since you are passing as a argument javascript will treat every parameter as a string so do this change your code will be a good one.
Post back if you have any doubts.

Regards
Ramanan Kalirajan
Mar 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Chris | last post by:
Can anyone point me to some code that will display messages, in a seperate window, from javascipt. ie effectively a trace window? TIA Chris
12
by: Stanley | last post by:
Hi, I'd like to write a HTML page which can help me directly log in my Yahoo!mail or Gmail account without typing user name and password. Basically, I want to set up a link, click it and pop up...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
4
by: jackchang1 | last post by:
It took me a while to figure out this error functiom method1(){ alert(); } by this error message missing ; before statement functiom method1(){ alert(); } why Javascript can't tell me...
6
by: haijdp | last post by:
Hi, I am using the following javascript method inside a js file. function createDivRow(label,text) { var formedTd = '<tr><td>' + label + '</td><td> <a href="#"...
4
by: jehugaleahsa | last post by:
Hello: I am going through an effort to standardize web applications for my company. We are trying to figure out the best practices for security, error handling, etc. I've just done a large...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.