get select text with jquery in table - jquery-clone

i have a table with this select:
<tr class="tr_clone">
<td>
<select style="width:200px" name="itens[]" class="itemname">
<option value="0"></option>
<option value="1">Item A</option>
<option value="2">Item B</option>
<option value="3">Item C</option>
</td>
in jquery, I am trying to get the text of the selected item (Item A when 1 is selected). I am then putting this value to another text box, (named 'note'). I can put the index value but not the text of the select.
$("table").on('change', '.itemname', function() {
var prtCont = $(this).parent().parent();
var code = prtCont.find('.itemname').val();
prtCont.find('.note').val(code);
});
what should I change in my jquery?

Well, 1st close the select tag.
<tr class="tr_clone">
<td>
<select style="width:200px" name="itens[]" class="itemname">
<option value="0"></option>
<option value="1">Item A</option>
<option value="2">Item B</option>
<option value="3">Item C</option>
</select>
</td>
</tr>
To get the text of the selected item you can do:
$('.itemname option:selected').html()
Your jQuery is a little confuse, for me is better:
$('.itemname').on('change' , function() {
var prtCont = $(this).parent().parent();
code = $(this).val(); // Get the value
text = $('.itemname option:selected').html(); // Get the text
prtCont.find('.note').val(code + ' ' +text);
});

Related

How to get the value from the drop down box django? without submit button

How to get the value from the dropDown Box in Django Without Submit Button
<div class="single-shorter">
<form action="." method="GET">
<label>Sort By :</label>
<select name="val" id="val">
<option selected="selected" value="name">Name</option>
<option value="price">Price</option>
</select>
</form>
</div>
You can simple obtain it using Ajax but as mentioned in comments in dont want to use that u can use value attribute in option value and using event listner and window.loction.href we can obtain this... This is one example
<select id="foo">
<option value="">Your Dropdown</option>
<option value="http://www.google.com">x</option>
<option value="http://www.facebook.com">y</option>
</select>
<script>
document.getElementById("foo").onchange = function() {
if (this.selectedIndex!==0) {
window.location.href = this.value;
}
};
</script>
as u are using django use this and also dont want to change the value attribute
<select id="my_selection">
<option value="x" href="/link/to/somewhere">value 1</option>
<option value="y" href="/link/to/somewhere/else">value 2</option>
</select>
<script>
document.getElementById('my_selection').onchange = function() {
window.location.href = this.children[this.selectedIndex].getAttribute('href');
}
</script>

Capturing response values from multiple dropdowns in Loadrunner

I have to capture the values of options in the <select name="fromPort"> and <select name="toPort"> separately for correlation using loadrunner.
I have written the regular expression as
<select name="fromPort" class="form-inline">(.+?)</select>
for capturing from first but it shows that there is no match.
<form action="reserve.php" method="post">
<select name="fromPort" class="form-inline">
<option value="Paris">Paris</option>
<option value="Philadelphia">Philadelphia</option>
<option value="Boston">Boston</option>
<option value="Portland">Portland</option>
<option value="San Diego">San Diego</option>
<option value="Mexico City">Mexico City</option>
<option value="São Paolo">São Paolo</option>
</select>
<p>
<h2>Choose your destination city:</h2>
<select name="toPort" class="form-inline">
<option value="Buenos Aires">Buenos Aires</option>
<option value="Rome">Rome</option>
<option value="London">London</option>
<option value="Berlin">Berlin</option>
<option value="New York">New York</option>
<option value="Dublin">Dublin</option>
<option value="Cairo">Cairo</option>
</select>
<p></p>
<div class="container">
<input type="submit" class="btn btn-primary" value="Find Flights"/>
</div>
</form>
When I try with notepad++, there is a checkbox to select when there are multiple lines of response to be captured. When I check it, the same regular expression is working.enter code here
My answer is less elegant, considering you have multiple similar tags involved on the from/to side of the house. I am going to suggest backing up, capturing with a LB condition of either \"fromPort" class=\"form-inline\"\n" or \"toPort" class=\"form-inline\"\n" to an end tag of "\n"
You will wind up with two string variables, such as "Correlated_from" and "Correlated_to" which contain the option values. Next is conversion to an array structure.
There are likely a dozen ways that you can take the string apart, but I would recommend a function that breaks on the newline character, jumps the first "\t\t" Character in the substring, saving out the value between that and the next "<" character. As noted previously, there are likely a dozen ways to break up this string with a defined pattern to get to the substring which interests you.
By adhering to the standard LoadRunner pseudo array structure, this opens up the use of the standard LoadRunner functions for assignment of a variable from a pseudo array - The lr_paramarr_* function set.
You can try this
Well what i have done is.
Extracted all the options from the select matching select tag using this
(?:<select name="(fromPort|toPort)" class="form-inline">\s+)([\w\W]+?)(?=\s+<\/select>)
Than split each option as single element into an array.
Than extracted value from each option using this regex.
(?<=\s*?<option value=")(.*?)(?=">.*?<\/option>)
let str =`<form action="reserve.php" method="post">
<select name="fromPort" class="form-inline">
<option value="Paris">Paris</option>
<option value="Philadelphia">Philadelphia</option>
<option value="Boston">Boston</option>
<option value="Portland">Portland</option>
<option value="San Diego">San Diego</option>
<option value="Mexico City">Mexico City</option>
<option value="São Paolo">São Paolo</option>
</select>
<p>
<h2>Choose your destination city:</h2>
<select name="toPort" class="form-inline">
<option value="Buenos Aires">Buenos Aires</option>
<option value="Rome">Rome</option>
<option value="London">London</option>
<option value="Berlin">Berlin</option>
<option value="New York">New York</option>
<option value="Dublin">Dublin</option>
<option value="Cairo">Cairo</option>
</select>
<p></p>
<div class="container">
<input type="submit" class="btn btn-primary" value="Find Flights"/>
</div>
</form>`
let selectAllOption = str.match(/(?<=<select name="(fromPort|toPort)" class="form-inline">\s+)[\w\W]+?(?=\s+<\/select>)/g);
let splitedOptions = selectAllOption.map(e=>e.split('\n'))
let finalValues = splitedOptions.map(e=>{
return e.map(ele=>{
return ele.match(/(?<=\s*?<option value=")(.*?)(?=">.*?<\/option>)/g)
})
})
console.log(finalValues);
I extract the select using LB="select id="xxxx"" and RB="</select"
Then use something like the following to get either all options (if I want to randomize which one is submitted the script, or I pick the already selected one, if I want to submit what the default selection is. Whenever I need to use complex regular expressions I usually hardcode a test case into a temporary test action to test the logic out before hitting the actual application.
TestExtract()
{
int matchCt, ord;
char *arrayMemberValue;
char * bufferToSearch =
"<option value=\"8183011816-1:USD\"";
char * bufferToSearch2 =
" <option value=\"8171245851-1:USD\">xxxxxx5851 - DDA 008171245851</option>"
" <option value=\"863006969-1:USD\">xxxxxx6969 - DDA 000863006969</option>"
" <option value=\"863006977-1:USD\">xxxxxx6977 - DDA 000863006977</option> ";
char * bufferToSearch3 =
" <option value=\"125\">AIRLINE PILOT</option> "
" <option value=\"008\" selected=\"selected\">SELF EMPLOYED</option>"
" <option value=\"232\">RECEPTIONIST</option>";
char * bufferToSearch4 =
"<select id=\"occupation\" name=\"occupation\" onchange='occupationChange();' class='form-control required' data-validate='dropdown'> "
" <option value=\"125\">AIRLINE PILOT</option> "
" <option value=\"008\" selected=\"selected\">SELF EMPLOYED</option>"
" <option value=\"232\">RECEPTIONIST</option>"
"</select>"
"<select name=\"_address_state_pr\" id=\"_address_ state_p\" class=\"form-control\">"
" <option value=\"Adjuntas\" selected>Adjuntas</option>"
" <option value=\"Aguada\"> Aguada</option>"
" <option value=\"Aguadilla\">\tAguadilla\t</option>"
" <option value=\"Aguas Buenas\">\tAguas Buenas\t</option>"
"</select>";
lr_output_message ("Test Regexp Extract");
lr_save_param_regexp (
bufferToSearch,
strlen(bufferToSearch),
"RegExp=option value=\"(.*?)\"",
"ResultParam=fromAccount",
LAST );
lr_output_message ("Value of fromAccount in buffer1 = %s", lr_eval_string("{fromAccount}"));
lr_save_param_regexp (
bufferToSearch2,
strlen(bufferToSearch2),
"RegExp=option value=\"(.*?)\"",
"Ordinal=All",
"ResultParam=reMatchesParam",
LAST );
matchCt = lr_paramarr_len("reMatchesParam");
lr_message("%d match(es) found in buffer2.", matchCt);
for (ord=1; ord <= matchCt; ord++)
{
arrayMemberValue = lr_paramarr_idx("reMatchesParam", ord);
lr_message("Member %d value: %s", ord, arrayMemberValue);
}
// find selected option - use a non capturing group to skip the greedy RegExp for prior Option values
// https://regex101.com/
// PCRE (?:value=".*").*value=(.*?) selected
lr_save_param_regexp (
bufferToSearch3,
strlen(bufferToSearch3),
"RegExp=(?:value=\".*\").*value=\"(.*?)\" selected",
"Ordinal=1",
"ResultParam=reSelectedOption",
LAST );
lr_output_message ("Value of selected option in buffer3 = %s", lr_eval_string("{reSelectedOption}"));
// normally will use web_reg_save_param_ex with LB and RB to extract the specific select statement
lr_save_param_regexp (
bufferToSearch4,
strlen(bufferToSearch4),
"RegExp=select id=\"occupation\"(.*?)</select>",
"Ordinal=1",
"ResultParam=reOptionGroupOccupation",
LAST );
lr_output_message ("Value of option group occupation in buffer4 is = %s", lr_eval_string("{reOptionGroupOccupation}"));
lr_save_param_regexp (
lr_eval_string("{reOptionGroupOccupation}"),
strlen( lr_eval_string("{reOptionGroupOccupation}")),
"RegExp=(?:value=\".*\").*value=\"(.*?)\" selected",
"Ordinal=1",
"ResultParam=reSelectedOption",
LAST );
lr_output_message ("Value of selected occupation option in buffer4 = %s", lr_eval_string("{reSelectedOption}"));
return -1; // iterate no further
}

Transfer Value from drop down to a

I need some help ...
I need the location drop down box to determine the appropriate inbox the form should be sent to.
ex if I choose Houston from the drop down box it will send it to the PayrollUSA email.
Im currently using a radio button to make the selection but i would like to automate with the drop down.
Im pretty new to this but im sure theres a if statement that can tie them together...
im using .asp for this.
<input type="radio" name="payroll" value="PayrollUSA#mail.com" checked="checked">US Payroll
<input type="radio" name="payroll" value="PayrollCAN#mail.com">CAN Payroll
<input type="radio" name="payroll" value="PayrollUK#mail.com">UK Payroll
<input type="radio" name="payroll" value="PayrollHK#mail.com">HK Payroll
Drop down selection
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option selected >Select</option>
<OPTION>Calgary</OPTION>
<OPTION>Chicago</OPTION>
<OPTION>Hong Kong</OPTION>
<OPTION>Houston</OPTION>
<OPTION>London</OPTION>
<OPTION>Los Angeles</OPTION>
<OPTION>Montreal</OPTION>
<OPTION>New York</OPTION>
<OPTION>New York Corporate</OPTION>
<OPTION>Philadelphia</OPTION>
<OPTION>San Francisco</OPTION>
<OPTION>Toronto</OPTION>
<OPTION>Toronto Corporate</OPTION>
<OPTION>Vancouver</OPTION>
</SELECT>
If you need the option value to be held then try this:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="">Select an Option</option>
<option <% if Business_Unit= "PayrollCAN#mail.com" then %> selected <% End if %> value="PayrollCAN#mail.com">Calgary</option>
<option <% if Business_Unit= "PayrollUSA#mail.com" then %> selected <% End if %> value="PayrollUSA#mail.com">Chicago</option>
</select>
etc. for each option and same value may be used for different option displays
I imaging this should just be html based. So your option menu should look like:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="-1">Select an Option</option>
<OPTION value="PayrollCAN#mail.com">Calgary</OPTION>
<OPTION value="PayrollUSA#mail.com">Chicago</OPTION>
<OPTION value="PayrollHK#mail.com">Hong Kong</OPTION>
<OPTION value="PayrollUSA#mail.com">Houston</OPTION>
<OPTION value="PayrollUK#mail.com">London</OPTION>
<OPTION value="PayrollUSA#mail.com">Los Angeles</OPTION>
<OPTION value="PayrollCAN#mail.com">Montreal</OPTION>
<OPTION value="PayrollUSA#mail.com">New York</OPTION>
<OPTION value="PayrollUSA#mail.com">New York Corporate</OPTION>
<OPTION value="PayrollUSA#mail.com">Philadelphia</OPTION>
<OPTION value="PayrollUSA#mail.com">San Francisco</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto Corporate</OPTION>
<OPTION value="PayrollCAN#mail.com">Vancouver</OPTION>
</SELECT>
You can use the same value multiple times if needed

How to make date and time form values insert into one column?

I have a form where the user selects a date and time. The user's selections represent the time and date they want specific answers, which they enter in the same form, to display. Then I grab the selected values and insert them into a table: cse_result_summary. Right now my code is inserting them correctly.
I'm using this jquery plugin for the date. Time is just a simple select. Something I did not think about before I finish the form was how I would compare today's date to the show_date.
The code below will work for the show_date, but the problem is with the time. Even if the date is greater, but the time is not, it will have to wait for that time to display. I would like it to display at that specific time and date. When its after that date and time it should no longer matter the time it is.
Since I'm inserting the date and time in different columns, I'm wondering if its possible to insert them into one column? That way I will only have to compare todayDate > formDate:
<cfset dtToday = Now() />
<cfif DateFormat(dtToday, "yyyy--mm--dd") gte DateFormat(getdates.show_date)
&& TimeFormat(dtToday) gte timeformat(getdates.show_time)>
different file (form file)
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate"
value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary
( show_date, show_time,monthly_enter_date,monthly_past_date )
VALUES
( '#newdate#','#time_used#',getdate(),'#month_date_show#' )
</cfquery>
Assuming your database field type is date/time you could do something like this:
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate" value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<Cfset combinedDateTime="#newdate #time_used#">
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary (show_date, show_time,monthly_enter_date,monthly_past_date, *yourcolumname*)
VALUES ('#newdate#','#time_used#',getdate(),'#month_date_show#', <cfqueryparam cfsqltype="cf_sql_timestamp" value="#combinedDateTime#">)
</cfquery>

Drop down menu in famo.us

I am trying to just display a drop down menu using famo.us:
var selector = new Surface({
size:[200,200],
content: ' <select>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
</select>'
});
what is wrong in this?
You need to add backslashes to extend the string to each next line.
Here is what that would look like..
var selector = new Surface({
size:[200,200],
content: ' <select> \
<option value="1"> 1</option> \
<option value="2"> 2</option> \
<option value="3"> 3</option> \
</select>'
});
Hope it helps!