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

How to loop through FORM elements?

The following code will allow me to loop through FORM tags but not the
elements in them. I may have five forms on one page. How do I loop through
form elements in the forth FORM?

private SHDocVw.InternetExplorer IE_Inst = new
SHDocVw.InternetExplorerClass();
.....
mshtml.IHTMLDocument2 HTMLDocument =
(mshtml.IHTMLDocument2) this.IE_Inst.Document;
mshtml.IHTMLElementCollection forms = HTMLDocument.forms;

foreach (mshtml.HTMLFormElementClass el in forms)
{

strType = el.outerHTML;
}

Once I'm in a particular FORM, I want to find certain input fields and fill
in values.

Thanks,
Brett
Nov 17 '05 #1
2 13323

"Brett" <no@spam.com> wrote in message
news:OU**************@TK2MSFTNGP14.phx.gbl...
The following code will allow me to loop through FORM tags but not the
elements in them. I may have five forms on one page. How do I loop
through form elements in the forth FORM?

private SHDocVw.InternetExplorer IE_Inst = new
SHDocVw.InternetExplorerClass();
....
mshtml.IHTMLDocument2 HTMLDocument =
(mshtml.IHTMLDocument2) this.IE_Inst.Document;
mshtml.IHTMLElementCollection forms = HTMLDocument.forms;

foreach (mshtml.HTMLFormElementClass el in forms)
{

strType = el.outerHTML;
}

Once I'm in a particular FORM, I want to find certain input fields and
fill in values.

Thanks,
Brett


I'm currently getting around the problem by looping through all elements in
the Doc:

foreach (mshtml.IHTMLElement wbrElm in wbrAll)
{
// Assign the inner html values of the input to our variables
//look for only INPUT types
if(wbrElm.tagName.ToLower() == "input" &&
wbrElm.outerHTML.IndexOf("name", 1) > 0)
{
strName = wbrElm.getAttribute("name", 0).ToString();
Debug.WriteLine(wbrElm.tagName.ToLower() + " -- " + wbrElm.outerHTML);
// We are only interested in filling text boxes,
// and only interested in a specific one, i.e. "q"

if (strName != null && strName.ToLower() == userNameFormField)
// Set the "value" with the setAttribute method.
wbrElm.setAttribute("value", userNameValue, 0);
if (strName != null && strName.ToLower() == passwordFormField)
// Set the "value" with the setAttribute method.
wbrElm.setAttribute("value", passwordValue, 0);
}
} //end for each

Not the best technique.

Brett
if (strName != null && strName.ToLower() == passwordFormField)
// Set the "value" with the setAttribute method.
wbrElm.setAttribute("value", passwordValue, 0);
}
} //end for each
Nov 17 '05 #2
Hi,

Is this in the client side? if so you better use javascript , this code
could give you an idea

for(int i =0 ; i < document.forms[3].elements.length; i ++ )
alert( document.forms[3].elements[i].tagName );

note that I did not test it, so it may have errors
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Brett" <no@spam.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...

"Brett" <no@spam.com> wrote in message
news:OU**************@TK2MSFTNGP14.phx.gbl...
The following code will allow me to loop through FORM tags but not the
elements in them. I may have five forms on one page. How do I loop
through form elements in the forth FORM?

private SHDocVw.InternetExplorer IE_Inst = new
SHDocVw.InternetExplorerClass();
....
mshtml.IHTMLDocument2 HTMLDocument =
(mshtml.IHTMLDocument2) this.IE_Inst.Document;
mshtml.IHTMLElementCollection forms = HTMLDocument.forms;

foreach (mshtml.HTMLFormElementClass el in forms)
{

strType = el.outerHTML;
}

Once I'm in a particular FORM, I want to find certain input fields and
fill in values.

Thanks,
Brett


I'm currently getting around the problem by looping through all elements
in the Doc:

foreach (mshtml.IHTMLElement wbrElm in wbrAll)
{
// Assign the inner html values of the input to our variables
//look for only INPUT types
if(wbrElm.tagName.ToLower() == "input" &&
wbrElm.outerHTML.IndexOf("name", 1) > 0)
{
strName = wbrElm.getAttribute("name", 0).ToString();
Debug.WriteLine(wbrElm.tagName.ToLower() + " -- " +
wbrElm.outerHTML);
// We are only interested in filling text boxes,
// and only interested in a specific one, i.e. "q"

if (strName != null && strName.ToLower() == userNameFormField) // Set
the "value" with the setAttribute method.
wbrElm.setAttribute("value", userNameValue, 0);
if (strName != null && strName.ToLower() == passwordFormField) // Set
the "value" with the setAttribute method.
wbrElm.setAttribute("value", passwordValue, 0);
}
} //end for each

Not the best technique.

Brett
if (strName != null && strName.ToLower() == passwordFormField) // Set
the "value" with the setAttribute method.
wbrElm.setAttribute("value", passwordValue, 0);
}
} //end for each

Nov 17 '05 #3

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

Similar topics

1
by: Jeremy Langworthy | last post by:
Hi I have a dynamicly generated form (well the elements are at least) that looks something like this: while( not end of returned records): <input name="plan_id" type="checkbox" id=""...
1
by: Randi | last post by:
Hi is there any other way of writing this function, I am just wondering if there is another way of reading through the array like using a for loop or something. Can you do this using a for loop? ...
1
by: Dave R | last post by:
Hey everybody! I'm in dire need of some help. I'm trying to loop through all the elements in a form, and determine whether or not the field is visible. Kinda like this: var TForm =...
3
by: brett | last post by:
Using DOM in IE, how can I loop through FORMs and access FORM elements in a specific form? For example, www.hotmail.com has about 13 forms. I believe the one displayed is dependent on the URL. If...
5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
6
by: Ed Jay | last post by:
<disclaimer>New to js.</disclaimer> I have several pages, each with menues comprising checkboxes or radio boxes within the same form. I presently 'brute force' clear the buttons with individual...
12
by: usa-99 | last post by:
Hi there I have following function which is called on load of page. function checkFieldContent(form) { var field; for(i = 0; i < form.elements.length; i++) { field = form.elements; if...
9
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x =...
15
by: dhtml | last post by:
Title says it. If I use a for in loop on an HTML collection, I get length twice. <!DOCTYPE HTML> <html lang="en"> <head> <title>length twice</title> </head> <body> <form...
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
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: 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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.