By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

textbox.width=textbox.width*0.85 Text Resize Control Help

P: 6
I am trying to develop a resize module i can include on my pages that calculates the size of input fields based on the screen resolution...
I can already detect the screen resolution, and i have the width / height multiplier for every resolution i need to support... my problem is this...


I want the include file to be totally universal so heres my plan
I will use CSS styles to set the current text box size... i want the javascript to then detect the screen size and apply the correct multiplier to the textbox size...

Where i run into issues is getting the current textbox size and adding it to itself, it seems i cannot use the current textbox size because the javascript is loading before the text boxes themselves...

I am triggering this java on the BODY ONLOAD event....

Expand|Select|Wrap|Line Numbers
  1. frmMain.txtLogin.style.width=frmMain.txtLogin.style.width*intWidthMultiplier
the input box would be coded like this

[HTML]<input type=text name=txtLogin style="height:20; width:200; font-size:12" />
[/HTML]

Thanks in advance for any help you can add.
Nov 30 '07 #1
Share this Question
Share on Google+
4 Replies


gits
Expert Mod 5K+
P: 5,378
hi ...

welcome to TSDN ...

in case you call the script onload the textbox is ready to use and to be manipulated ...

but i think you have to add units to the width-value ...

Expand|Select|Wrap|Line Numbers
  1. text_box_reference.style.width = your_width + 'px';
note: the retrieved value should have that unit already, so you have to strip the value out of that before using math-operations :)

kind regards

ps: you should add the units too in the elements style-declaration ...
Nov 30 '07 #2

P: 6
Im not familiar with units i will have to research these, i am executing the java function on Body Onload, when i try to use this code

Expand|Select|Wrap|Line Numbers
  1. frmMain.txtLogin.style.width=frmMain.txtLogin.style.width*intWidthMultiplier
then it errors stating "Invalid arguement"
Dec 1 '07 #3

gits
Expert Mod 5K+
P: 5,378
hi ...

have a look at the following example:

[HTML]<script type="text/javascript">
function resize_tb(tb_id) {
var tb = document.getElementById('my_tb');
tb.style.width = tb.style.width.replace(/px$/, '') * 2 + 'px';
}
</script>
<body onload="resize_tb('my_tb');">
<input style="width:400px" type="text" id="my_tb" name="test" value="test"/>
</body>
[/HTML]
the invalid arg error should come from another line of your code since the one you posted has no arguments?

kind regards
Dec 1 '07 #4

P: 6
for(i=0; i<document.frmMain.elements.length; i++)
{
if(document.frmMain.elements[i].type=="text")
{
document.frmMain.elements[i].style.width=document.frmMain.elements[i].style.width * intWidthMultiplier;
}
}
}

I continue to get invalid arguement with this.....
The error is pointing to this line
document.frmMain.elements[i].style.width=document.frmMain.elements[i].style.width * intWidthMultiplier

the variable intWidthMultiplier during my tests has a value of 0.050
Dec 3 '07 #5

Post your reply

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