Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: onclick problem

  1. #1
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default onclick problem

    hi to all

    i want to change the properties of some objects. is it possible
    i am sending my code please go through this and tell is it possible

    Code:
    <html>
    	<head>
    		<script language="javascript">
    		function put()
    		{
    			//here it redirects to insert page
    		}
    		function putupdate()
    		{
    /*here i want to write code to find the record of entered number and put those values at relevent fields, i want to hide "Insert" button and also change the method which is going to call "Update" button to update()*/
    		}
    		function updateing()
    		{
    			//here it redirects to update page		}
    		</script>
    	</head>
    	<body>
    		<form name="f1">
    		<br><br>
    		<center>
    		Number:<input tpe="text" name=t1"><br>
    		Name:<input type="text" name="t2"><br>
    	Address:<input type="textarea" rows=4 cols=4 name="ta1"><br><br>
    		<input type=button value="Insert" onClick="put()">
               <input type="button" value="Update" onClick="putupdate()">
    	</body>
    </html>
    regards

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Use this:
    Code:
    document.forms['formname'].elements['buttonname'].onClick = null
    to clear the onClick event on a button.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your quik reply

    the code what you sent is to set onclick to null. if i want to set new method for onclick can i use as follows:

    document.forms['formname'].elements['buttonname'].onClick = 'newFunction()'

    is it correct.

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Nope. You need to set it as:
    Code:
    document.forms['formname'].elements['buttonname'].onClick = function() {newFunction()}
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i used like this. bu ti amgetting errors only. where i am doing mistakes
    Code:
    <html>
    	<head>
    		<script language="javascript">
    		function tes()
    		{
    			window.alret("hi");
    			document.forms['f1'].elements['b1'].onClick = function() {tep()}
    		}
    		function tep()
    		{
    			window.alert("hello");
    			document.forms['f1'].elements['b1'].onClick = function() {tes()}
    		}
    		</script>
    	</head>
    	<body>
    		<form name="f1">
    		 <input type=button onclick="tes()" name="b1" value="click here">
    		 </form>
    	</body>
    </html>

    i am getting th e following error "object does't support this method or property"
    regards

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Why do you need to repeat the function?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The problem in red color

    Code:
    <html>
    	<head>
    		<script language="javascript">
    		function tes()
    		{
    			window.alret("hi");
    			document.forms['f1'].elements['b1'].onClick = function() {tep()}
    		}
    		function tep()
    		{
    			window.alert("hello");
    			document.forms['f1'].elements['b1'].onClick = function() {tes()}
    		}
    		</script>
    	</head>
    	<body>
    		<form name="f1">
    		 <input type=button onclick="tes()" name="b1" value="click here">
    		 </form>
    	</body>
    </html>
    It should be

    Code:
    window.alert("hi");
    I wonder what you are trying to do

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Plus that creates an indefinite loop, which could possibly crash a client's computer .
    I wonder what you are trying to do
    I don't see any point either.
    - Mike

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    In javascript, it is:

    onclick

    Not:

    onClick.

    You can do this:

    Code:
    function bob(){
    alert('bob');
    }
    element.onclick=bob;
    or this:

    Code:
    function bob(){
    alert('bob');
    }
    element.onclick=function(){bob();};
    or:

    Code:
    element.onclick=function(){alert('bob');};
    or even:

    Code:
    element.onclick=new Function("alert('bob')");
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    I looked into this a bit further and there were a few other typos/syntax errors. This works:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<script language="javascript">
    		function tes(el)
    		{
    			alert("hi");
    			el.onclick = function(){tep(this)};
    		}
    		function tep(el)
    		{
    			alert("hello");
    			el.onclick = function(){tes(this)};
    		}
    		</script>
    </head>
    <body>
    		<form name="f1">
    		 <input type=button onclick="tes(this)" name="b1" value="click here">
    		 </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •