473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

onClick and input type="text"

Hi!

In my form I have table which cells contain input objects of type="text"
which initially are disabled. I would like to activate them by clicking on
them. However because input object does not support onClick event (or maybe
I am wrong?) I use onClick events of table cells. And it works as required
in IE 6. I click on the input object and the onClick event of the cell is
raised. But it does not work in Firefox (I have not yet checked the other
browsers). Does anyone have an idea how to solve this problem? I would not
like to add more objects to this form, the most I am interested in achiving
in Firefox the same effect like in IE.

Regards
Silmar
Jul 23 '05 #1
3 3231
Silmar wrote:
In my form I have table which cells contain input objects of
type="text" which initially are disabled. I would like to activate
them by clicking on them.


That makes not much sense. Disabling a form control means that
clicking it should have no effect, so what you want to do, is to
mimic the behaviour of a non-disabled control for a disabled one,
so you could simply do this without disabling and should get what
you intend.

ciao, dhgm
Jul 23 '05 #2
> However because input object does not support onClick event (or maybe I am
wrong?)


Small errata - onClick event is fired for enabled (disabled = 0) input
objects.

Regards
Silmar
Jul 23 '05 #3
Silmar wrote:
Hi!

In my form I have table which cells contain input objects of type="text" which initially are disabled. I would like to activate them by clicking on them. However because input object does not support onClick event (or maybe I am wrong?) I use onClick events of table cells. And it works as required in IE 6. I click on the input object and the onClick event of the cell is raised. But it does not work in Firefox (I have not yet checked the other browsers). Does anyone have an idea how to solve this problem? I would not like to add more objects to this form, the most I am interested in achiving in Firefox the same effect like in IE.

Regards
Silmar


Hi Silmar.

Disabled inputs in moz are deader than Francisco Franco...IE still
fires clicks on them which bubble but Firefox does nothing. Just for
fun, I threw this together (even though I basically agree with Dietmar
Meier's usability assessment above). Use a class for flagging.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

form {
width: 120px;
}
input {
margin: 6px;
}
input.normal {
border: 1px #000 solid;
}
input.enab {
border: 2px #000 solid;
}

</style>
<script type="text/javascript">

function getLeft(node)
{
var lPos = node.offsetLeft;
while (node = node.offsetParent)
lPos += node.offsetLeft;
return lPos;
}

function getTop(node)
{
var tPos = node.offsetTop;
while (node = node.offsetParent)
tPos += node.offsetTop;
return tPos;
}

window.onload = function()
{

function handler(e)
{
var tgt, ipt;
if ((e = e || window.event)
&& (tgt = e.srcElement || e.target))
{
ipt = tgt.nextSibling;
ipt.disabled = !ipt.disabled;
if (!ipt.disabled)
{
ipt.focus();
ipt.select();
}
}
}

var i = 0,
ipt,
div,
ipts = document.getElementsByTagName('input');
while (ipt = ipts.item(i++))
if (/\benab\b/.test(ipt.className))
{
ipt.disabled = true;
div = document.createElement('div');
div.style.position = 'absolute';
div.style.left = getLeft(ipt) + 'px';
div.style.top = getTop(ipt) + 'px';
div.style.width = ipt.offsetWidth + 'px';
div.style.height = ipt.offsetHeight + 'px';
div.onclick = handler;
ipt.parentNode.insertBefore(div, ipt);
}
}

</script>
</head>
<body>
<form>
<input class="enab" type="text" value="foo">
<input class="enab" type="text" value="feh">
<input class="normal" type="text" value="hah">
</form>
</body>
</html>

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: j.t.w | last post by:
Hi All. I'm having a problem with my Date of Birth textbox. When I open the ..htm file, the "DoB" textbox is flat with a border. All of my other textboxes are sunken and are yellow. When I...
1
by: Neil Zanella | last post by:
Hello, I would like to use CSS to apply a width of 100% to all <input> elements, but to only those that have an type attribute set to "text", without affecting check boxes, radio buttons, etc......
9
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
1
by: i_dvlp | last post by:
I'm attempting to size a table and its proving to be difficult, when the <td> contain input type="text" It seems any width spec using <col width="50"> works fine, but only when it applies to...
2
by: alxasa | last post by:
Hello, I am hoping someone can help me with this. I need a javascript function, which sits inside a <input type="text" name="firstname"> line of code. Now, if someone starts typing fine, but when...
3
by: joe | last post by:
Is it OK to have multiple: <script type="text/javascript" src="funcs1.js"></script> <script type="text/javascript" src="funcs2.js"></script> <script type="text/javascript"...
9
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( ...
2
by: Warren Tang | last post by:
Hello, everyone Can I make a <input type="text"tag transparent? I mean I can see through it and see the background of its container. Regards Warren
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.