CodeChargeMVP
Posts: 473
|
| Posted: 12/02/2010, 4:56 AM |
|
Hi,
I´m struggling with this stuff,
I request your minds to make an easyer general example I let you here
some interesting related links:
http://blog.mastykarz.nl/measuring-the-length-of-a-stri...ing-javascript/
http://bytes.com/topic/javascript/answers/89923-determi...g-length-pixels
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
dragoon
Posts: 173
|
| Posted: 12/02/2010, 6:29 AM |
|
in the second link you got an working example
document.getElementById('ruler').offsetWidth will give you exact pixels of the span
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 12/02/2010, 7:16 AM |
|
I Post here the evolution of the issue.
Hi Waldek,
I Think this article could be handly for some stuff I´m working on,
I need to know how much pixels does a certain String, so I do (This is only a test):
String.prototype.VisualLength() = function()
{
var ruler = window.document.getElementById("ruler");
ruler.innerHTML = this;
return ruler.offsetWidth;
}
function prueba()
{
var s="This is a very largue text.";
var Length = s.VisualLength();
alert(Length) —-> return 122 down my question
//I´ve understand than this 122 value is the quantity of pixels than should have
// an input object by showing all the context of the string s without trimming
// ¿is that right? or may i miss understand the article.
window.document.getElementById("myinputobject").style.width = Length;
window.document.getElementById("myinputobject").value = s;
//The input object only shows: This is a very largue
}
the fuction prueba runs on the onclick event of the inputobject.
What I´m searching for is the quantity of pixels than I should give for example to a input object or a select object to fix exactly his width with the length of the text than contains.
¿is that possible?
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 12/02/2010, 7:18 AM |
|
Ok is good, gotta take a look.
Quote dragoon:
in the second link you got an working example
document.getElementById('ruler').offsetWidth will give you exact pixels of the span
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 12/03/2010, 12:06 AM |
|
dragoon,
I´m doing this and still getting only the visible quantity of pixels:
¿what´s my mistake?
String.prototype.VisualLength = function(s)
{
var ruler = window.document.getElementById("ruler");
ruler.innerHTML = s;
return ruler.offsetWidth;
}
function prueba()
{
var s = "This is a very largue text.";
//var d = "text.";
var Length = s.VisualLength(s);
//var Length1 = d.VisualLength(d);
//alert(s.length);
alert(Length);
alert(Length1);
//alert(window.document.getElementById("ruler").offsetWidth);
//window.document.getElementById("intervenciones_desembolsaIntDesAno").style.width = Length + Length1;
window.document.getElementById("intervenciones_desembolsaIntDesAno").style.width = Length;
window.document.getElementById("intervenciones_desembolsaIntDesAno").value = s;
}
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 12/09/2010, 3:04 AM |
|
¿any suggestion?
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |