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

Javascript set button width depending on the length of Text value

200 100+
Good day,

I have button with no width specified.
The text value of the button differs, so i left it with no width.

It automatically sets the width but the problem is it to wide with about 5 spaces on each side of text letting the button look stupid.

I thought of working out the Text in a javascript function then set the length of the button.

Expand|Select|Wrap|Line Numbers
  1. <input id="{Description}" type="button" value="{Description}" onClick="{@name}.click();" style="background-color: #f9f9f9; height: 23px;"></input>
  2.  
Please help
Jan 11 '10 #1

✓ answered by acoder

Check the default padding for the button.

5 3906
Dormilich
8,658 Expert Mod 8TB
The text value of the button differs, so i left it with no width.
erm, but you explicitly set a width …

additionally, HTML input elements should always be empty: <input … type="button">
Jan 11 '10 #2
acoder
16,027 Expert Mod 8TB
Check the default padding for the button.
Jan 11 '10 #3
Dormilich
8,658 Expert Mod 8TB
you may also use the <button> element, if you like.
Jan 11 '10 #4
xNephilimx
213 Expert 100+
same as acoder, the problem is the padding for sure, a button will always accommodate it's with according to the text, unless you specify a fixed size. You have to be careful about the box model though, in mozila/webkit compatible browsers the padding (and border) is not taken in account in the width, so if the width is 10 and the padding (left and right) is 5 the with will still be 10px but you will see it as if it is 20px wide.
http://www.w3.org/TR/CSS21/box.html
Jan 11 '10 #5
ismailc
200 100+
Thank You All :)

Got it going - i'm surpirsed no javascript needed.

Expand|Select|Wrap|Line Numbers
  1. overflow: visible;padding: 2px 2px 2px 2px;
  2.  
Jan 12 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: vinu | last post by:
I have a javascript file named select.js. This is a file which is use to pop up a calendar, when clicked on a calendar icon in an ASP file. have a close button in the calendar. When i click on the...
3
by: Richard | last post by:
I have tried to create a javascript puzzle where by the grid is filled with numbers from 1 to 26 and another grid listed 1 to 26 where each number relates to a letter. Once you figure out the...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.