473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript function throwing error

1 New Member
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 1137
RamananKalirajan
608 Contributor
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(maxCha r). 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
6073
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
22117
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 the Yahoo/Gmail page. What technology is most appropriate for this kind of work? My current solution is not so satisfying: I download Yahoo!Mail page
12
9643
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(" & Chr(34) & PopUpWindowTitle & Chr(34) & ", " & Chr(34) & CurrentEventDetails & ")" strTemp += "<BR><A HREF='#' onClick='" & PopupLink & "'>" & EventName & "</A><BR>" The problem I have is that when the string variables or contain a string with an...
2
3059
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 what I'm hoping to achieve. I've never before had to use Javascript closures, but now I do, so I'm making an effort to understand them. I've been giving this essay a re-read: http://jibbering.com/faq/faq_notes/closures.html
4
1515
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 directly
6
2026
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="#" onclick="javascript:eventHandlerFunction("'+text+'")">'+text+'</a></td></tr>'; return formedTd; }
4
2985
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 amount of work to figure out the built-in ASP .NET security features (which was fairly easy to do). So now I am tackling error handling. What we would like to do is show a JavaScript Alert box with the error information in it. Here is the code I...
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.