473,387 Members | 1,453 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,387 software developers and data experts.

Dynamic width of a text input field in a form

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>
</form>

The result is exactly the same as if I hadn't added the style
attribute. This works with other inline styles, say <a>, why not with
<input>? I've searched the web for possible reasons, without turning
up anything.

Just so you know, the text field is for inputting long URLs, often far
longer than the width of the browser. Thus, setting a static width
isn't necessary to indicate the expected length of an entry. I've
considered using textarea, but have ruled this out as Mozilla only
wraps on whitespace. It's for a URL shortening application I'm working
on--you can find it here: http://linkfrog.net

Thanks,
Walter Gildersleeve
Freiburg, Germany

Nov 8 '05 #1
1 7798
NullBock wrote:
I'm trying to create a form with a text-input (not textarea) that
expands to the size available, using CSS.
Then you should have posted to c.i.w.a.stylesheets, right? I'm setting
followups there and exceptionally quoting your entire message for that
reason.
I thought that a simple display:block would work:
That's a natural idea, but on second thought, it should not work. Fields
must be expected to have default widths, and the display property should
not disturb that.
<form>
<div>
<input type="text" style="display: block">
</div>
</form>

The result is exactly the same as if I hadn't added the style
attribute.
It's the same even if you add width: auto, which is somewhat odd.
This works with other inline styles, say <a>, why not with
<input>? I've searched the web for possible reasons, without turning
up anything.
<a> elements have no default width set, but <input type="text"> elements
have, either via an explicit size="..." attribute or with that attribute
defaulted (to 20, typically).

But setting width: 100% helps (even without display: block).

ObHTML: I would still use size="..." with a relatively large value (say
42), if a wide field is preferred, according to the principle that your
style sheet might or might not be applied.
Just so you know, the text field is for inputting long URLs, often far
longer than the width of the browser. Thus, setting a static width
isn't necessary to indicate the expected length of an entry. I've
considered using textarea, but have ruled this out as Mozilla only
wraps on whitespace. It's for a URL shortening application I'm working
on--you can find it here: http://linkfrog.net

Thanks,
Walter Gildersleeve
Freiburg, Germany


Using <input type="text"> rather than <textarea> looks right, despite
the problems. A URL cannot logically contain a line break, so physical
line breaks should be avoided too.
Nov 8 '05 #2

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

Similar topics

4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
5
by: drdave | last post by:
Hi, I have 6 forms being generated using coldFusion, they are named special1, special2 special3 and so on.. in these forms I have a link to open a new window. I am trying to pickup the...
1
by: philin007 | last post by:
Hi , I am having a page where leave is applied. - In this page 1 new rows is created dynamically everytime the 'Add row' button is pressed - Each row has a begin date text field and beside it a...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
7
by: gregincolumbus | last post by:
Hello I have used chained selects to populate two selects. When the user chooses from first select, he is presented with the populated data for the 2nd select. The result is a list of numbers. ...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
4
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.