How to set default value for input inside select option - laravel

Hello Guys I Have select and many options and i have input inside on of these options and i want to set default value for it. My Code is bellow
<label for="cars">Choose a car:</label>
<select name="cars" id="cars" class='select2'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
i want to set default value for input id = 'searchfor'.
i tried this code bellow but it doesn't work
<select name="cars" id="cars">
<input id='searchfor' type='search' value='car1' placeholder='search for your car'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
when i open the select i don't see the value for this input

You cannot put an text input element inside a select element
Using MDN as a reference, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select the only permitted content for a select element is;
Zero or more <option> or <optgroup> elements.
So it is not valid html for a select input element to itself contain an input element
See also for info;
Put input inside select

Related

inspection of code shows code that should not be there or be there as it is

I'm working with an application written in dHTML and running on a Windows 10 laptop using the Apache server. I have some lines of simple code that generate a 2 SELECT statements as follows.
print " Choose an effort: <SELECT NAME='echoice' CLASS='slcts' SIZE='16' STYLE='width:180px' ONMOUSEOVER=\"setStatus2('Only efforts with measures your authorized to work with are shown.');\" ONMOUSEOUT=\"setStatus2(' ');\" ONCHANGE=\"Loadem('choice');\">\n";
foreach $iline (#ilines) {
print "<OPTION VALUE='$iline'>$iline</OPTION>\n";
}
print "</SELECT>\n";
print "Choose $what: <SELECT NAME='choice' CLASS='slcts' SIZE='16' STYLE='width:180px'>\n";
if ($cmfunction eq 'MeasureDescriptions' && $action eq 'U') {
print "<OPTION SELECTED VALUE='new'>new</OPTION>\n";
$imo = 1;
}
foreach $mline (#mlines) {
$thestr = ($i == 0 && !$imo) ? 'SELECTED' : '' ; # Select 1st measure if not a single model.
print "<OPTION $thestr VALUE='$mline'>$mline</OPTION>\n";
$i++;
}
print "</SELECT>\n";
I don't seem to be able to change the contents of this field as long as the first select is there. First I put a new unique character in the 2nd SELECT text each test to tell me if I'm executing the module version I think I am. I always see the unique character.
I have tried the following.
comment out the inner 2 print statements,
change >new< to >new1<,
assign 'dog' to the 0 position of the mlines array, and
add a print after the Option loop to add a 'dog' option.
In all four cases, the choice SELECT had the same options as it had before any of the tests (1-4) were implemented. But if I remove the first select,
I can then modify the options of the 2nd select. The debugger image of the above code follows with both selects.
Choose an effort: <SELECT NAME='echoice' CLASS='slcts' SIZE='16' STYLE='width:180px' ONMOUSEOVER="setStatus2('Only efforts with measures your authorized to work with are shown.');" ONMOUSEOUT="setStatus2(' ');" ONCHANGE="Loadem('choice');">
<OPTION SELECTED VALUE='all'>all</OPTION>
<OPTION VALUE='Health'>Health</OPTION>
<OPTION VALUE='HealthCare'>HealthCare</OPTION>
</SELECT>
Choose a measure !: <SELECT NAME='choice' multiple CLASS='slcts' SIZE='16' STYLE='width:180px' ONMOUSEOVER="setStatus2('Only measures your authorized to work with are shown. Select a measure for a formal definition.');" ONMOUSEOUT="setStatus2(' ');" ONCLICK='doFRef(event,this,this.form)'>
<OPTION SELECTED VALUE='new'>new</OPTION>
<OPTION VALUE='HEComp90'>HEComp90</OPTION>
<OPTION VALUE='HECompAtBirth'>HECompAtBirth</OPTION>
<OPTION VALUE='healthy'>healthy</OPTION>
<OPTION VALUE='infant'>infant</OPTION>
<OPTION VALUE='maternal'>maternal</OPTION>
<OPTION VALUE='stillbirths'>stillbirths</OPTION>
</SELECT>
The debugger code with only one select follows. I changed new to new1 and added the line and line2 options. But if I put the first select back in,
I can't modify the 2nd select and it contains what is shown in the 1st debugger image.
<OPTION SELECTED VALUE='new'>new1</OPTION>
<OPTION VALUE='line'>line</OPTION>
<OPTION VALUE='HEComp90'>HEComp90</OPTION>
<OPTION VALUE='HECompAtBirth'>HECompAtBirth</OPTION>
<OPTION VALUE='healthy'>healthy</OPTION>
<OPTION VALUE='infant'>infant</OPTION>
<OPTION VALUE='maternal'>maternal</OPTION>
<OPTION VALUE='stillbirths'>stillbirths</OPTION>
<OPTION VALUE='line2'>line2</OPTION>
</SELECT>
I don't understand this. Any help will be appreciated. It must be me.
Thanks,
craigt
It was me. There is an ONLOAD process that executed another process that preps
the content of that field that was not written correctly. I've corrected that process and all works as expected now. This question is closed. And I apologize for my oversight and thank everyone that took a look.

How to capture values from dropdown in JMeter

For code like below:
<div class="col-xs-4 col-sm-4 col-md-4 select-me show_me del_nxt" style="display: block;">
<select class="prime" name="primary" id="primary" onchange="newsecondary(this)">
<option value="none" id="1200">---Select main---</option>
<optgroup label="dummy1">
<option value="abc-2-1">abc</option>
<option value="xyz-2-1">xyz</option>
</optgroup>
<optgroup label="Dummy2">
<option value="abc1-2-1">abc1</option>
<option value="C1-2-1">C1</option>
<option value="D1-2-1">D1</option>
</optgroup>
</select>
<span class="Error"></span>
</div>
How to capture random value from dropdown list? thanks in advance.
Scenario is we have 4 drop downs with same type of html code as above.
Unless user selects any value from first drop down, another wont get enabled. this is how these 4 dropdowns are dependant on previous dropdown value .
Since content is html, the most maintainable way is to use CSS Selector Extractor based on this syntax:
Configuration would be the following:
You may use Regular Expression Extractor added to your request.
With the Regular Expression:
option value="([a-zA-Z0-9])+"
To ectract random value you need to set Match No to 0 as shown below
You may test your RegExp here regexr.com
Read more about Regular Expressions
If you want to select a random value and forget - go for HTML Links Parser
If you need the selected value anywhere else - you can extract it using i.e. XPath Extractor, it allows executing arbitrary XPath queries.
Get text of the selected option:
//select/optgroup/option/#selected/parent::*/text()
Get all options for optgroup with the label of dummy1
//select/optgroup[#label='dummy1']/option/#value
etc.

How to get an index of specific text in dropdown using vbscript code(.vbs)?

I am working on vbscript. I am writing script for selecting value from dropdown.
In my scenario, I want to select a value from dropdown using the text which resides in option tag i.e <option>value<option>
Request you to provide code for selecting value in dropdown using value not by index of value.
Thank you in advance. Please reffer below html code for reference.
<select id="mydropdown" onchange="getServiceDetails();" name="mydropdown">
value="[]"
<option value="-1">Select value</option>
value="[]"
<option value="0920102049">value 1</option>
value="[]"
<option value="0060217015">value 2</option>
</select>
This will do it.
Sub SelectOptionByInnerHTML(selectID, text)
Dim list, opt
Set list = document.getElementById(selectID)
For Each opt In list
If opt.innerHTML = text Then
opt.selected = true
Exit Sub
End If
Next
End Sub
Usage:
SelectOptionByInnerHTML "mydropdown", "value 2"

Xpath to get the value of an element with Selected property

For the following XMl file,
<select id="pet" title="Pet" class="x8" onchange="" name="pet">
<option></option>
<option selected="" value="abc">Dog</option>
<option value="def">Cat</option>
<option value="ghi">Rabbit</option>
</select>
What is the Xpath to be able to get the value of the option with "Selected" property? (I need to get "abc")
One possible way to get value attribute of option element having selected attribute :
/select/option[#selected]/#value
That would take all options
/select/option
That would take 2-nd option and read value attribute from it.
/select/option[2]/#value

xpath for selecting multiple elements from drop down

I am trying to extract some information from an html page. Consider the drop down select list below:
<select name="ctl00$MainContent$ddlColor" onchange="chageColor(this);setTimeout('__doPostBack(\'ctl00$MainContent$ddlColor\',\'\')', 0)" id="ctl00_MainContent_ddlColor" class="input" style="width:175px;">
<option selected="selected" value="">Color</option>
<option value="00114743-03|large|0|03">CHARCOAL</option>
<option value="00114743-04|large|2|04">BLACK</option>
</select>
It has 3 values, "Color", "CHARCOAL" and "BLACK".
Now if I view the source and copy XPATH of "CHARCOAL" using google chrome, I get
//*[#id="ctl00_MainContent_ddlColor"]/option[2]
However, I want to extract the information as "CHARCOAL" and "BLACK". I want this to be applied on multiple pages where the drop down list might contain more or less number of elements. However, I always want to skip the first element, which will be "Color". How to do this ?
Here you are ..
//select/option[not(contains(., 'Color'))]/text()
You can skip the first option by it's position by this
//select/option[position() > 1]/text()
I hope this could help

Resources