Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 23-08-2008, 01:23 AM   #1 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default onclick in html - javascript not being called


i have this webpage in which i am trying to dynamically add a text input box. I haven't got as far as to see if what i am trying to do is happening. I am still stuck at getting my click button to add the input box. I don't know what I am doing wrong.

The addtextbox function is supposed to add the element.

On clicking on the button Click, the function is supposed to be called. I added the alert call to check if the function is called.
Code:
<html>
    
  <head>
    <title></title>
  </head>
  <body>
      <script language="javascript">
		function addtextbox(){
		alert("ok, function called");
		var frm=document.forms[0];
		var newtxt=document.createElement('input');
		newtxt.setAttribute('type','text');
		newtxt.setAttribute('value','new box');
		newtxt.setAttribute('value','formvalue[]');
		frm.appendChild(newtxt);
}		
		;   
   </script>
    <form action="index.php" method="get">
    <input name="formvalue[]" type=text value="default value"/>

    <input type="button" value="Click to add box" onclick()="addtextbox();"/>
    <input type="submit" />
    
        
        
</form>
  </body>
</html>
__________________
Life is too short. Have fun.
ilugd is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 23-08-2008, 02:38 AM   #2 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,785
Default Re: onclick in html - javascript not being called

remove the brackets from onclick()
Your Code
Code:
<input type="button" value="Click to add box" onclick()="addtextbox();"/>
Change to
Code:
<input type="button" value="Click to add box" onclick="addtextbox();"/>
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Old 23-08-2008, 02:46 AM   #3 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: onclick in html - javascript not being called

@charan. Thanks a lot. It works now. Guess too much of learning java made me confused with how html works.
__________________
Life is too short. Have fun.
ilugd is offline  
Old 23-08-2008, 02:47 AM   #4 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: onclick in html - javascript not being called

it's onclick on onclick()
use vim/emacs, makes life easy, always.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 23-08-2008, 02:51 AM   #5 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,785
Default Re: onclick in html - javascript not being called

Quote:
Originally Posted by ilugd View Post
@charan. Thanks a lot. It works now. Guess too much of learning java made me confused with how html works.
welcome
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's Your Computer Called ? MetalheadGautham Chit-Chat 29 27-02-2008 10:12 AM
Help on Javascript and html needed Kalyan Programming 3 05-11-2007 12:20 PM
Need Some software called star Doc i_omkar Software Q&A 3 17-11-2006 01:35 PM
What will Longhorn be called? sms_solver QnA (read only) 61 29-08-2004 10:46 AM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:10 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2