473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set width of text input to physical text width

I have a grid. When the focus is put on a cell an input is created with the
value being the cell's text. I would like to size the input to the physical
width of the text. Ideas?

John

function editCell (cell) {

if (document.getEl ementById) {
cell.normalize( );
var input = document.create Element('INPUT' );
input.setAttrib ute('value', cell.firstChild .nodeValue);
input.setAttrib ute('size', cell.firstChild .nodeValue.leng th); //RATHER
THAN SET THE SIZE, I WOULD PREFER TO SET STYLE WIDTH

input.onblur = function (evt) { setCell(this.pa rentNode,this.v alue); };
input.onclick = function (evt) {
evt.cancelBubbl e = true;
if (evt.stopPropag ation)
evt.stopPropaga tion();
};

cell.replaceChi ld(input, cell.firstChild );

input.focus();
input.select();
}

}
Jul 20 '05 #1
1 17339
Doh! I just set the input widths in CSS to 100% and it does what I want.

John

"johkar" <no********@lin k.net> wrote in message
news:hL******** ********@newsre ad4.news.pas.ea rthlink.net...
I have a grid. When the focus is put on a cell an input is created with the value being the cell's text. I would like to size the input to the physical width of the text. Ideas?

John

function editCell (cell) {

if (document.getEl ementById) {
cell.normalize( );
var input = document.create Element('INPUT' );
input.setAttrib ute('value', cell.firstChild .nodeValue);
input.setAttrib ute('size', cell.firstChild .nodeValue.leng th); //RATHER THAN SET THE SIZE, I WOULD PREFER TO SET STYLE WIDTH

input.onblur = function (evt) { setCell(this.pa rentNode,this.v alue); }; input.onclick = function (evt) {
evt.cancelBubbl e = true;
if (evt.stopPropag ation)
evt.stopPropaga tion();
};

cell.replaceChi ld(input, cell.firstChild );

input.focus();
input.select();
}

}

Jul 20 '05 #2

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

Similar topics

179
44457
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
2
4992
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I haven't found a way to do this. I tried <span style="width:20em"> <input type="text"> <img width="25px" src="...">
157
16461
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript to adjust my page to the viewer's browser window dimensions and this would sure be great information to have. Thanks .... Dennis
8
23495
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
17
27900
by: Piers Lawson | last post by:
If the following is displayed in IE6 or FireFox, the text box forces the second DIV to expand beyond its 15em width. Is there a way to have the text box fit within the DIV (preferably without losing its default borders)? Thank you in advance Piers <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
1
7864
by: NullBock | last post by:
Hi, I'm trying to create a form with a text-input (not textarea) that expands to the size available, using CSS. I thought that a simple display:block would work: <form> <div> <input type="text" style="display: block"> </div>
13
14273
by: Martin Herbert Dietze | last post by:
Hi, I need to calculate the physical length of text in a text input. The term "physical" means in this context, that I consider 7bit-Ascii as one-byte-per character. Other characters may be longer, e.g. cyrillic would be 2 bytes per character. Is there a safe and easy way to notice non-7bit-Ascii input? Cheers,
4
1666
tolkienarda
by: tolkienarda | last post by:
hi all i am printing out a bunch of html code with a php script and i am not sure if my html syntax or my php syntax, everything works and displays the way i want but the width tags for the text inputs don't work, anyway here is the php code that prints the html $result = mysql_query("SELECT * FROM costs"); while ($row = mysql_fetch_row($result)) { $final = $row + $row; $savings = $row - $final; echo '<tr>'; echo...
2
2274
by: xtian | last post by:
Hi, I have been having some trouble with getting a column to be a fixed width. I have a table with 11 columns, so it doesn't all fit in a normal browser window. One of the cells has a "?" and then a text input, but because the table keeps minimizing the width of the column, it puts the ? and the text input on different lines, creating a row that is much taller than I would prefer, and it just looks gross. I have set the width using...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
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
9052
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...
0
6788
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
5442
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
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.