Click here to Skip to main content
16,020,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How find inputs in one form in html with htmlagilitypack?
I want to find input of all of form in html code but want to find inputs forms seprate.
for example this html:

XML
<html><body>
    <form id="form1">
      <input name="foo1" value="bar1" />
      <!-- Other elements -->
    </form>
    <form id="form2">
      <input name="foo2" value="bar2" />
      <!-- Other elements -->
    </form>
</body></html>



now I want to find input for form1 and then input for form2 and ....
then i want to get information in inputs.
please help me.
Thank you!
Posted
Comments
David_Wimbley 19-May-13 13:22pm    
Can you not handle this using jquery? it would be easier (in my opinion)...you can find all the inputs and their values, then pass back the values to your c# code using ajax or just plain posting to it.
e.v.r 19-May-13 14:43pm    
thanks,
no, i need to know inputs are which form.
can u writ code for me? my code is here:

HtmlNodeCollection forms = doc.DocumentNode.SelectNodes("//form");
if (forms != null && forms.Count > 0)
{
FormMethod = forms[0].GetAttributeValue("method", "POST").ToUpper();
HtmlNodeCollection inputs = doc.DocumentNode.SelectNodes("//input");
foreach (HtmlNode input in inputs)
{
string TypeName = "";
if (input.Attributes.Contains("type"))
TypeName = input.Attributes["type"].Value.ToString();


if (
string.Compare(TypeName, "button", true) != 0 &&
string.Compare(TypeName, "image", true) != 0

)
{
try
{
InputsControls += input.Attributes["name"].Value.ToString() + "\r";
}
catch (Exception)
{
}
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900