Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Adding onclick stuff to an INPUT through javascript

Adding onclick stuff to an INPUT through javascript

p.ross
11-23-2005, 11:14 PM
I have an INPUT box, for the sake of brevity it shall hitherto be known as turkey, that I want to edit. Unfortuinately for me, there html page that it is located in is read only. Luckly, in the HEAD of the page, it loads a javascript file that is not read only.

Now, is there a way through javascript that I can edit turkey to add something like "onclick="javascript:dofunction()""?

pccode
11-24-2005, 12:19 AM
This should work in FF and IE.


//adds the event handler when the page loads
onload = function() {
document.getElementById('turkey').setAttribute('onclick','testit()');
}

//clicking the link below will test if the attribute was set
function showevent() {
alert(document.getElementById('turkey').getAttribute('onclick'));
}

//clicking the button below will test if the event handler is working
function testit() {
alert('it works');
}

// if the input doesn't have an id, you can use the name instead
// document.forms[0].turkey.setAttribute('onclick','dofunction()');


<form>
<input type="button" id="turkey" name="turkey" value="TEST">
</form>
<br><br>
<a href=http://codingforums.com/archive/index.php/"javascript:showevent()">test</a>


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Anyone knows to clear the contents of the window !!! in javascript
Automatically generates color tags(<color="red">,</color>)
document.getElementByID() Issues
Netscape Problems :-(
problem with an ImagePreview js
Can function RETURN a value?
do I need a random script script or not?

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics