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

Control collection in javascript

I have a .net application that I am trying to add some javascript code
to for a client-side execution. What I want to do is resize all the
HTML text fields on my web form, but instead of writing a line for
each text box I would like to loop through a collection of controls
and resize the control if it is a text field. Is there a way to do
this in javascript? The function below is what I have been toying with
for the past couple of hours. Another idea was to use a css, but I
can't find an element for the text field. Thanks in advance for any
help.

function Test()
{
Tarray = new Object;
Tarray = document.Form1.children
for (var prop in Tarray)
{
//document.writeln(Tarray.toString);
var s;
s = prop
if (Left(s, 3) == "btn")
{
prop.height = "20px";
}
}
}
Jul 23 '05 #1
3 5180
Robert Bull wrote:
I have a .net application that I am trying to add some javascript code
to for a client-side execution. What I want to do is resize all the
HTML text fields on my web form, but instead of writing a line for
each text box I would like to loop through a collection of controls
and resize the control if it is a text field. Is there a way to do
this in javascript? The function below is what I have been toying with
for the past couple of hours. Another idea was to use a css, but I
can't find an element for the text field. Thanks in advance for any
help.

function Test()
{
Tarray = new Object;
Tarray = document.Form1.children
for (var prop in Tarray)
{
//document.writeln(Tarray.toString);
var s;
s = prop
if (Left(s, 3) == "btn")
{
prop.height = "20px";
}
}
}


<script type="text/javascript">
function test() {
var f = document.forms['yourFormName'];
if (f) {
f = f.elements;
}
var i = f.length;
while (i-- > 0) {
if (f[i].type == 'text' && f[i].style) {
f[i].style.height = '2px';
}
}
}
</script>
<form name="yourFormName">
<input type="text" name="test1">
<input type="checkbox" name="test2">
<input type="radio" name="test3">
<input type="text" name="test4">
<input type="button" name="test5"
value="Set text input height" onclick="test();">
</form>

Tested and working in IE 6.0.2800, Firefox 1.0PR, Opera 7.54 and Mozilla
1.7.3

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
Grant Wagner wrote:
[snip]
<script type="text/javascript">
function test() {
var f = document.forms['yourFormName'];
if (f) {
f = f.elements;
}
var i = f.length;
while (i-- > 0) {
if (f[i].type == 'text' && f[i].style) {
f[i].style.height = '2px';
}
}
}
</script>

[snip]

A slightly more concise version is below (tested in Safari). It
assumes that you pass the reference to the form name when you call the
function.

e.g. test(this.form)

if you are calling it from a button in a form:

<script type="text/javascript">
function test(f) {
if (document.forms) {
for (var i=0; i<f.length; i++) {
if (f[i].type == 'text' && f[i].style) {
f[i].style.height = '2px';
}
}
}
}
</script>
Jul 23 '05 #3
Rob
Thanks a lot Grant...it worked like a charm.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

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

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
6
by: Tom Rowton | last post by:
This one has me a bit confused and I'm not finding what I need in the MSDN or by searching these forums, so here goes... I have a rather large, complex code-in-page WebForm (don't ask) and a...
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
4
by: Marius Trælnes | last post by:
Hello! I am about to make a class/control that creates tabbing functionality. The result is in HTML/CSS/JavaScript output. My question is: Within the tabs I want to simply add user controls...
2
by: sunilthk | last post by:
Hi All, I have a question. If javascript is disabled how asp.net determines which control has caused the post back. As we know that when we clicks on the button the buttons name goes with posted...
2
by: ccgatvolvo | last post by:
Here is the rendered output from my page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.