Picture In Response to a Answer What The Webpage looks Like
<input name="ftitle" class="inputbox ui-autocomplete-input" type="text" autocomplete="off">
I need to add value= to the above HTML input element How do I go about doing this? For the life of me, I can Not Figure it out.
Edit: I need this because I need to fill in a text box that is on a web page that does not contain the value= in it. But if I right click on it and add attribute value= then I can change the text through my program.
I am using C# web browser control so I'm using
HtmlElement NewAttribute = doc.GetElementById("ftitle");
So when everything is said and done it will look like this.
<input name="ftitle" class="inputbox ui-autocomplete-input" type="text"
autocomplete="off" value="">
Here what I got so far if it helps to see what I am up to. this is all for a different web page but I am doing the same thing but I need to add the class "value"
private void Generate_Click(object sender, EventArgs e)
{
HtmlDocument doc = wbNewProject.Document;
HtmlElement wbJobName = doc.GetElementById("Name"); //lblcontact.text
HtmlElement wbEngineer = doc.GetElementById("engineer-lookup"); //
HtmlElement wbSalesEng = doc.GetElementById("SalesEngineerUserId");
HtmlElement wbLocation = doc.GetElementById("Location");
HtmlElement wbBidDate = doc.GetElementById("BidDate");
HtmlElement wbPriorApproval = doc.GetElementById("PriorApproval"); //True or False
HtmlElement wbTakeOff = doc.GetElementById("TakeOffComplete"); //True or False
HtmlElement wbProject = doc.GetElementById("RoleType"); //Design/Build or Plan/Spec
HtmlElement element = wbNewProject.Document.GetElementById("ftitle");
try
{
wbJobName.SetAttribute("value", lblJobName.Text);
if (lblContact.Text.Contains("Dan"))
wbSalesEng.SetAttribute("value", "2");
if (lblContact.Text.Contains("Kelley"))
wbSalesEng.SetAttribute("value", "3");
if (lblContact.Text.Contains("Erv"))
wbSalesEng.SetAttribute("value", "4");
if (lblContact.Text.Contains("Marc"))
wbSalesEng.SetAttribute("value", "5");
if (lblContact.Text.Contains("Terry"))
wbSalesEng.SetAttribute("value", "6");
if (lblContact.Text.Contains("Chad"))
wbSalesEng.SetAttribute("value", "7");
if (lblContact.Text.Contains("Jacob Lenertz"))
wbSalesEng.SetAttribute("value", "10");
if (lblContact.Text.Contains("Terry"))
wbSalesEng.SetAttribute("value", "11");
if (lblContact.Text.Contains("Nate"))
wbSalesEng.SetAttribute("value", "12");
wbLocation.SetAttribute("value", lblLocation.Text);
wbBidDate.SetAttribute("value", lblBidDate.Text);
if (lblPriorApp.Text.Contains("Yes"))
wbPriorApproval.SetAttribute("value", "true");
if (lblPriorApp.Text.Contains("No"))
wbPriorApproval.SetAttribute("value", "false");
if (lblTakeOff.Text.Contains("Done"))
wbTakeOff.SetAttribute("value", "true");
if (lblTakeOff.Text.Contains("Not Done"))
wbTakeOff.SetAttribute("value", "false");
wbEngineer.SetAttribute("value", lblEngineer.Text);
wbProject.SetAttribute("value", lblProject.Text);
}
catch { }
}
document.getElementById(elementName).value = "your value";
$('#elementName').val() = "your value";
Both approaches will require you to create an Id on your element. However, jQuery will also allow you to select your element by other means other than an Id.
This is also simple, use the SetAttribute Method:
HtmlElement element = doc.GetElementById("ftitle"); //Your have this, correct?
element.SetAttribute("value", "your value");