Html code/example of dropdown:
<select class="ng-valid ng-dirty ng-touched" style="max-width: 235px" ng-model="blogerj" ng-options="blogerj.long_name for blogerj in blogerj track by blogerj.id">
<option class="" value="">[Choose...]</option>
<option label="label 1" value="1">Text Content 1</option>
<option label="label 2" value="2">Text Content 2</option>
<option label="label 3" value="3">Text Content 3</option>
<option label="label 4" value="4">Text Content 4</option>
</select>
If I just set attribute making it selected then it dont work because button for submit appears only when element is selected.
I also tried just to click element to open dropdown and then again click desired option but again it gave me no results.
foreach (GeckoHtmlElement geckoHtmlElement in gwBrowser.Document.GetElementsByTagName("select"))
{
if (geckoHtmlElement.GetAttribute("class") == "ng-valid ng-dirty ng-touched")
{
geckoHtmlElement.Click();
}
}
Actually it finds element but clicking dont do anything.
So maybe there is any fancy js method to select that dropdown?
From the portion class="ng-valid ng-dirty ng-touched" it looks like there is AngularJS at work here - because angular usually uses the prefix ng-. Angular can intercept user actions and take control of how your web page controls behave.
Related
i coded an select filter for my website:
Filter
<div class="row">
<select class="event-type-select" id="selection" >
<optgroup label="categorygroup1">
<option value="category1">category1</option>
</optgroup>
<optgroup label="categorygroup2">
<option value="category2">category2n</option>
<option value="category3">category3</option>
</optgroup>
<optgroup label="categorygroup3">
<option value="category4">category4</option>
</optgroup>
</select>
</div>
<div class="row">
<button type="submit" class="btn btn-default"> filter </button>
</div>
</form>
before selecting anything in the "selection-window" on the website you read "category1". i guess thats default(?).
but if i selected a category (and that works: you can read in the "selection-window" e.g. category3) and then click on the "filter"-button the website refreshes but in the "selection-window" you again read "category1" and not the selected category e.g "category3". i guess the selection doesn't work right.
how can i solve this that when clicking the button you still read your selected category?
also i want to display the selected option on a different part of the website.
my current code for this:
<script type='text/javascript'>
var m = document.getElementById("selection").value;}
document.write(m);
</script>
that as well doesn't work.
i hope you can understand what i mean, my english is pretty bad. sorry for that.
First, the question essentially contains 2 questions packed into one, don't do that.
Second, you are simply missing the preselection of the <select> field.
the selection doesn't work
When submitting a form the values are sent to the server. The server processes the values and renders the page again. Therefore you have to adjust the rendering according to the selected value. Lets say you simply pass the selected value to the view as string the view code could look like this:
#model string
...
<select class="event-type-select" id="selection" >
<optgroup label="categorygroup1">
<option value="category1" #if (Model == "category1") {<text>selected</text>}>category1</option>
</optgroup>
<optgroup label="categorygroup2">
<option value="category2" #if (Model == "category2") {<text>selected</text>}>category2n</option>
...
</select>
also i want to display the selected option on a different part of the website.
Then store the selection somewhere (e.g. a DB), retrieve the selected value before the different part is rendered and simply output it in the different part.
The script has an error, you should use a function:
function test()
{
var m = document.getElementById("selection").value;
alert(m);
}
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="row">
<select id="selection" class="event-type-select">
<optgroup label="categorygroup1">
<option value="category1">category1</option>
</optgroup>
<optgroup label="categorygroup2">
<option value="category2" selected="selected">category2n</option> <!-- with selected="selected" you set the default -->
<option value="category3">category3</option>
</optgroup>
<optgroup label="categorygroup3">
<option value="category4">category4</option>
</optgroup>
</select>
</div>
<div class="row">
<button type="submit" class="btn btn-default" onclick="test()"> filter </button>
</div>
</body>
</html>
Good morning.
I can not select an item from the drop-down list.
Did the following:
1) I entered the text
WebBrowser1.Document.GetElementById ("Advert_category_id").InnerText = "Wedding / Event Services";
2) Set the value using the following commands, in different sequences, as soon as not twisted.
WebBrowser1.Document.GetElementById("Advert_category_id").SetAttribute("selected", "selected");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("onchange");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("submit");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember ("value", "84");
The problem is that this code selects the option I need, but it does not appear in the field. Those. Only when you click on the field, after executing the code, you can see that the desired option is selected. But this approach is also not true, because
The following drop-down list named SUB CATEGORY does not load the required data (the data remains with the category selected by default - Professional)
3. I tried to experiment with different id-shniki. Nothing helps :(
The site itself https://list.asiandirectoryapp.com/advert/create
(You must register to view)
I made the second ack,
That would not waste time for registration
fovogaze#p33.org
qwerty123
The code of interest
<div style="display:none"><div class="form-group"><label class="control-label" for="Advert_city_id">City</label><select class="form-control" name="Advert[city_id]" id="Advert_city_id">
</select><div class="help-block error" id="Advert_city_id_em_" style="display:none"></div></div></div><div class="form-group"><label class="control-label required" for="Advert_category_id">Category <span class="required">*</span></label><select class="form-control" name="Advert[category_id]" id="Advert_category_id">
<option value=""></option>
<option value="35">Beauty, Health & Fitness</option>
<option value="19">Education</option>
<option value="21">Entertainment</option>
<option value="27">Food, Drink & Sweet Centres</option>
<option value="39">Home Services</option>
<option value="116">Jobs/Careers</option>
<option value="43">Motoring</option>
<option value="50">Other Services</option>
<option value="1">Professional</option>
<option value="51">Property Improvements</option>
<option value="84">Wedding/Event Services</option>
<option value="117">Whats On Guide</option>
</select><div class="help-block error" id="Advert_category_id_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_categoryList">Sub category <span class="required">*</span></label><select multiple="multiple" class="form-control" name="Advert[categoryList][]" id="Advert_categoryList">
<option value="2">Accountants</option>
<option value="4">Claims</option>
<option value="123">Clothing Manufacturers</option>
<option value="6">Estate & Letting Agents</option>
<option value="7">Finance/Mortgages</option>
<option value="8">Graphic & Web Design</option>
<option value="9">Immigration</option>
<option value="10">Information Technology</option>
<option value="11">Insurance</option>
<option value="13">Mobile Apps - Mobile Phones</option>
<option value="14">Online Marketing/ SEO</option>
<option value="18">Print</option>
<option value="15">Retail and Wholesale</option>
<option value="16">Solicitors - Lawyers</option>
<option value="17">Travel Agents</option>
</select><div class="help-block error" id="Advert_categoryList_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_name">Company Name <span class="required">*</span></label><input class="form-control" placeholder="Company Name" name="Advert[name]" id="Advert_name" type="text" maxlength="100" /><div class="help-block error" id="Advert_name_em_" style="display:none"></div></div>
P.S. I can fill out all the fields, press the buttons the same way, but with the drop-down list the trouble. Thank you for any help.
I had a similar problem but I chose to solve it by simply invoking a client-side javascript (with a parameter) that handles the manipulation of the dom objects.
I found that this way I can separate code too, keeping dom handling in the JS and application-code in the winforms. Itll also allow you to leverage any functionality provided by e.g. jQuery plugins wrapping the select.
It could look like this (not tested):
Object[] objArray = new Object[2];
objArray[0] = selectorID;
objArray[1] = valueToSet;
webBrowser1.Document.InvokeScript("SetSelector", objArray);
and in the client side:
function SetSelector(selectorID, valueToSet){
$('#'+selectorID).val(valueToSet); //or any function you'd like
}
I am trying to create a multiple choice select field in my .cshtml file that looks like this:
<select multiple="multiple" id="select-multiple" style="width:500px" name="MultipleSelect">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
</select>
I have a model that has a List<string> MultipleSelect that maps perfectly when i save my model. all the selected values get to the controller and are saved in the database. But when the page reloads the values don't show. I checked with the debuger and the MultipleSelect list gets filled with the values before the view gets loaded.
Should I use a diferent type for my MultipleSelect value or is this just not the right way to do this?
I have the following ASP:DropDownList on my aspx page:
<label>OT Code No.</label>
<asp:DropDownList runat="server" ID="ddlOvertimeCode" class="form-control" TabIndex="1"></asp:DropDownList>
Which renders as the following in HTML:
<select name="ctl00$MainContentPlaceHolder$ddlOvertimeCode" id="MainContentPlaceHolder_ddlOvertimeCode" tabindex="1" class="form-control">
<option selected="selected" value="0">-Select-</option>
<option value="1">1 - 10B PLES</option>
<option value="2">2 - Investigation</option>
<option value="3">3 - Arrest</option>
<option value="4">4 - Misc</option>
<option value="5">5 - EWW</option>
<option value="6">6 - Holiday</option>
<option value="7">7 - In-Lieu Holiday</option>
</select>
When submitted the form, I disable the DropDownList using the following code in my .cs file
ddlOvertimeCode.Attributes.Add("disabled", null);
I tried other methods of disabling the dropdownlist, however all of them would either override the bootstrap styling of the list or leave the dropdownlist able to be changed despite being grayed-out and ReadOnly. Adding the disabled attribute is the only way I could find to gray-out the box while leaving it's styling intact.
the problem arrises when the user withdraws the form, making it editable again, and the code re-enables the dropdownlist using the same method:
ddlOvertimeCode.Attributes.Remove("disabled");
removing the disabled attribute resets the dropdownlist and leaves me unable to alter DropDownList.SelectedValue from the codebehind.
I need a method of graying out the DropDownList and disabling it from the codebehind without overriding the bootstrap styling, and then returning it to an editable state, all while preserving the original selected value.
check if AutoPostBack="True"
code
thanx
If I have accessed a Select element on a website, how would I go about changing it's selected item?
I tried:
selectElement.SetAttribute("value", "30");
But this doesn't work.
Thanks!
With this html
<select id="a">
<option value="1">1</option>
<option value="2">2</option>
</select>
Doing this will select the second option
document.getElementById("a").selectedIndex = 1
see this jsfiddle example: http://jsfiddle.net/vJsvV/