Hello,
I'm trying to auto fill a email text field area on a website, the problem is there is more than one same email name, so it fills the first email field and not the second field.
they both are in different areas.
when I try to auto fill by doing webBrowser1.Document.GetElementById("email").SetAttribute("value", "[email protected]"); it fills out the first field, but I want the second field to be field and not the first field.
thanks in advance.
Loading
alex nonePosted Apr 2, 2012, 3:58 PM
if (webBrowser1.Document != null)
{
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement elem in elems)
{
String nameStr = elem.GetAttribute("name");
if (nameStr == "email")
{
webBrowser1.Document.GetElementById(nameStr).SetAttribute("value", "[email protected]");
}
}
}
I have tried using the code above which I got from msdn.microsoft website which uses GetElementsByTagName, the problem is it changes the first email field value and not the second one, however it does get both of email tags.
if possible could you please show me an example code, which I will learn from.
thank you.
Sam HobbsPosted Apr 2, 2012, 2:12 AM
I forgot about the Forms property of the HtmlDocument Class. That is useful for here. I think it will accomplish the same thing essentially as GetElementsByTagName to get all the "form" elements. Also I think elements["email"] will accomplish the same thing essentially as GetElementById("email") but I am not sure.
SenthilkumarPosted Apr 2, 2012, 12:27 AM
It happens when same id given to many controls. If it is server side control then you will get the compilation error. It is defined as HTML control.
You mentioned that you have these controls in the different form. Even through if you take like this.
document.getElementById('email').value then what happens, you are trying to identify the control by id in the rendered browser controls.
There are two solutions to fix this issue. Either change the name of the control. It will solve without any workaround.
If you want to identify your control even though two different forms then
If you want to know more than
http://www.javascript-coder.com/javascript-form/javascript-get-all-form-objects.phtml
Sam HobbsPosted Apr 1, 2012, 4:44 PM
Try using GetElementsByTagName to get all the "form" elements then use GetElementById for each of them. Understand? I think that will work.
alex nonePosted Apr 1, 2012, 4:02 PM
Sam HobbsPosted Apr 1, 2012, 3:43 PM