473,886 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Functions!

68 New Member
hi

I'm facing a small issue regarding the function

now what i want to do is, call a function without using Onchange or onclick or any of these options.

this is a simple code i have written: jus to get some idea

-------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script language=javascript>
  3. function diableitem()
  4. {
  5. document.try.text.style.backgroundColor = "#eeeeee";
  6.  
  7. }
  8. </script>
  9.  
  10. <body>
  11. <form name=try>
  12.  
  13. <input type=text name=num value=100>
  14.  
  15. disableitem()
  16.  
  17. </form>
  18. </body>
  19. </html>
-------------------------------------------------

i want to call this disableitem function.

im not able to do it here, as it jus prints "disableite m()" on the browser, doesnt call it.

Any help is appreciated.

Thank You.
Jul 24 '07 #1
8 1170
pbmods
5,821 Recognized Expert Expert
Heya, thanawala27.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

You're getting this error because document.try.te xt does not exist. Give your INPUT an id property, and then use document.getEle mentById() instead.
Jul 24 '07 #2
epots9
1,351 Recognized Expert Top Contributor
do what pbmods said and also call the function from the body tag, using the 'onload' attribute.
Jul 24 '07 #3
thanawala27
68 New Member
HI,

I TRIED WHAT YOU MENTIONED, BUT STILL THE FUNCTION IS NOT CALLED

THIS IS THE CODE I TRIED

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <html>
  4. <script language=javascript>
  5. function diableitem()
  6. {
  7. element = document.getElementById(num);
  8.  
  9. element.text.style.backgroundColor = "#eeeeee";
  10.  
  11. }
  12. </script>
  13.  
  14. <body>
  15. <form name=try>
  16.  
  17. <input type=text name=num value=100>
  18.  
  19. disableitem()
  20.  
  21. </form>
  22. </body>
  23. </html>
  24.  
  25.  
  26.  

I JUS WANT TO CALL THIS FUNCTION, WITHOUT USING ONCHANGE, OR ONCLICK.BUT IM FACING PROBLEMS WITH IT.

THANKS FOR ALL THE REPLIES
Jul 24 '07 #4
thanawala27
68 New Member
@epots9

I DON'T WANT TO CALL WHEN THE BODY IS LOADED. AS THERE IS SOME PROCESSING DONE, BEFORE THIS FUNCTION IS CALLED.

THANKS
Jul 24 '07 #5
epots9
1,351 Recognized Expert Top Contributor
HI,

I TRIED WHAT YOU MENTIONED, BUT STILL THE FUNCTION IS NOT CALLED

THIS IS THE CODE I TRIED

[html]

<html>
<script language=javasc ript>
function diableitem()
{
element = document.getEle mentById(num);

element.text.st yle.backgroundC olor = "#eeeeee";

}
</script>

<body>
<form name=try>

<input type=text name=num value=100>

disableitem()

</form>
</body>
</html>


[/html]


I JUS WANT TO CALL THIS FUNCTION, WITHOUT USING ONCHANGE, OR ONCLICK.BUT IM FACING PROBLEMS WITH IT.

THANKS FOR ALL THE REPLIES
give this a try:

Expand|Select|Wrap|Line Numbers
  1. function diableitem()
  2. {
  3. document.getElementById(num).style.backgroundColor = "#eeeeee";
  4. }
  5.  
and
[html]
<body onload="diablei tem();">
[/html]

give that a shot, but u do know that won't disable anything...just change the background color.

good luck
Jul 24 '07 #6
thanawala27
68 New Member
GOT IT!!!

to call a function without using ONCHANGE OR ONCLICK, following needs to be done
CALL THE FUNCTION BETWEEN <script> tags as shown below:


Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <script language=javascript>
  4. function disableitem()
  5. {
  6. alert ("VERY HAPPY!!!")
  7. }
  8. </script>
  9.  
  10. <body>
  11. <form name=try>
  12.  
  13. <input type=text name=num value=100>
  14.  
  15. <script type="text/javascript">
  16.   disableitem();
  17. </script>
  18.  
  19. </form>
  20. </body>
  21. </html>
  22.  
  23.  
IT WORKS FINE.

THANKS FOR ALL THE INPUTS FOLKS
Jul 24 '07 #7
gits
5,390 Recognized Expert Moderator Expert
hi ...

yes ... that works of course ... but when you use document.getEle mentById(); in your function i may (probably will) give you an error ... since the document dom is reliably ready in onload of the page ... so you cannot rely on the execution during load ... try it ;)

kind regards
Jul 25 '07 #8
pbmods
5,821 Recognized Expert Expert
thanawala27, please do not type in all-caps. Thanks!
Jul 25 '07 #9

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

Similar topics

7
1086
by: roger | last post by:
I'm having difficulties invoking a user defined table function, when passing to it a parameter that is the result of another user defined function. My functions are defined like so: drop function dbo.scalar_func go create function dbo.scalar_func() returns int
4
1612
by: Merlin | last post by:
Hi Imagine the following classes (A class diagram will help) BASE, A, B, C, D, E, F, G. A, B, C, D, G inherit from BASE. E, F inherit from D.
57
4323
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
1
1336
by: ashutosh | last post by:
hi, i am making the dll for clamav antivirus libraray so that i can make activex control for windows. i complied the library successfully and make the Libclamav.dll file using win32 Api project in debug mode. this dll file exports all the 21 function which is needed for clamscan.
2
2539
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I am really desperate now, because I havent' been able to locate the origin of the problem for a couple of days now.. PROBLEM: the message digest obtained differs each time I execute the code, but works perfectly when applying the "control", that...
14
2968
by: Christian Kaiser | last post by:
We have a component that has no window. Well, no window in managed code - it uses a DLL which itself uses a window, and this is our problem! When the garbage collector runs and removes our component (created dynamically by, say, a button click, and then not referenced any more), the GC runs in a different thread, which prohibits the DLL to destroy its window, resulting in a GPF when the WndProc of that window is called - the code is gone...
6
1650
by: cppnow | last post by:
Hello. I have a strange conceptual problem I'm trying to think about. I would like to build a library that allows the user to do the following: 1) User defined types: The user defines their own types as needed for their particular application and registers them with the library. class ClassA {};
4
2466
by: r_ahimsa_m | last post by:
Hello, I am learning WWW technologies in Linux. I created index.html file which I can browse with Firefox/Konqueror using URL localhost/~robert/rozgloszenia/index.html. The page looks fine but there's one strange problem: I have written some JavaScript code in functions.js file which seems to be ignored when called although I have JavaScript enabled in Firefox/Konqueror. For example in functions.js I have:
6
4558
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
1
10873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9593
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
7988
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
7141
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4632
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
4236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
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.