document.getelementbyid stop when finding a space in array - arrays

when i alert the array, he return the hole value, but when i try to get it from getElementById, he stop after the first space!??
I know, it's probably simple, but i dont understand the difference between the 2 answers
https://jsfiddle.net/prodeinfo/jvywho3y/
html
<div>
<div id="statusList"></div>
</div>
javascript
var countryLan = ["nothing","Also nothing",];;
alert(countryLan[1]);
document.getElementById('statusList').innerHTML += "<input type='text' value=" + countryLan[1] + " />";

Try this:
document.getElementById('statusList').innerHTML += "<input type='text' value='" + countryLan[1] + "' />";
as you can see, I added ' in value: value='" + countryLan[1] + "' />"
You had a problem because if you want to pass a text that contains spaces, you need to quote this text properly.
In your case, you just put the value from an array as is, without quotes and that's why there was only "Also" in your input.
Now it should work.
Good luck.

Related

input type="text" doesn't fetch the (1).pdf of a value?

In my database I have a column "name" type character varying and I have a value in my first row called "DBAE (1).pdf". When I want to put the name as a value in my input formular:
table += "<td>" + "<input type=\"text\" name=\"name\" value=" + rs.getString(i) + "\" readonly>" + "</td>";
with rs.getString(i) I only get the "DBAE" displayed without the "(1).pdf".
Do you know any reason why the rest is not being displayed?

Regex for picking up a color name from HTTP response

I am using Loadrunner and need to come up with a regex that will pick up a particular word from the HTTP response coming in and save it in a parameter.
The response looks like this:
\t\t\t\t\t<option value="Rose taupe" id="WD26" class="WD26">Rose taupe</option>\n
\t\t\t\t\t<option value="Myrtle" id="WD20" class="WD20">Myrtle</option>\n
\t\t\t\t\t<option value="Deep carmine pink" id="WD142" class="WD142">Deep carmine pink</option>\n
\t\t\t\t\t<option value="Wild Strawberry" id="WD66" class="WD66">Wild Strawberry</option>\n
\t\t\t\t\t<option value="Cream" id="WD72" selected="selected" class="WD72">Cream</option>\n
\t\t\t\t\t<option value="Tangerine yellow" id="WD94" class="WD94">Tangerine yellow</option>\n
I want to pick up the color that is selected in a drop down menu in the front end, in the response this color line has selected="selected" in it. This is however random for each instance hence the regex has to pickup the color name from the line which contains selected="selected".
I then have to use it in my script as follows:
web_reg_save_param_regexp ("ParamName=SelectedColor",
"RegExp=-regular expression here-",
"Ordinal=All",
LAST);
Thank you for your help!
The RegExp /<\s*option\s+(?=.*selected\s*=).*value\s*=\s*(?:"([^"]*)"|'([^']*)')/g will match the option tag with the selected attribute. The order of attributes is arbitrary. If attribute quotes may be ' then you need to handle the second match group, see example.
var s = '\t\t\t\t\t<option value="Rose taupe" id="WD26" class="WD26">Rose taupe</option>\n' +
'\t\t\t\t\t<option value="Myrtle" id="WD20" class="WD20">Myrtle</option>\n' +
'\t\t\t\t\t<option value="Deep carmine pink" id="WD142" class="WD142">Deep carmine pink</option>\n' +
'\t\t\t\t\t<option value="Wild Strawberry" id="WD66" class="WD66">Wild Strawberry</option>\n' +
'\t\t\t\t\t<option value="Cream" id="WD72" selected="selected" class="WD72">Cream</option>\n' +
'\t\t\t\t\t<option id="WD72" value=\'Cream\' selected="selected" class="WD72">Cream</option>\n' +
'\t\t\t\t\t<option value="Tangerine yellow" id="WD94" class="WD94">Tangerine yellow</option>\n';
var re = /<\s*option\s+(?=.*selected\s*=).*value\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
var m;
while (m = re.exec(s)) {
console.log("Selected color: " + (m[1]||m[2]) + ", match " + m[0]);
}
Below code will work.
web_reg_save_param_ex(
"ParamName=SelectedItem",
"LB/IC/DIG=id=\"^^^^\" selected=\"selected\"",
"RB=</option>",
"Ordinal=1",
SEARCH_FILTERS,
"Scope=ALL",
LAST);

how to click on javascript element in selenium

52 Low
This is how the html part is coded by developer
In case the ID of the link (tab) is not changing then you should put:
((JavascriptExecutor)driver).executeScript("document.getElementById('tab8').click()");
or even simplier (as Vivek noted):
((JavascriptExecutor)driver).findElement(By.id('tab8')).click();
In case the ID of the tab could potentially change you could search it by its text:
((JavascriptExecutor)driver).executeScript(
"var tabs= document.getElementsByTagName("a");" +
"var tabText= "52 Low";" +
"for (var i = 0; i < tabs.length; i++) {" +
" if (tabs[i].textContent == tabText) {" +
" tabs[i].click();" +
" break;" +
" }" +
"}");

Trying to create a h1 in Angular.Js and there's a space after my last letter

My code goes as followed
<h1> {{"Hello, " + "Angular!}} </h1>
and the output is: " Hello, Angular! ". as opposed to "Hello, Angular!"
Remove the space.
<h1>{{"Hello, " + "Angular!"}}</h1>
That's the space between <h1><space>{{Expression}}<space></h1>.
Change it as
<h1>{{"Hello, " + "Angular!"}}</h1>
You must remove the space between the <h1> tags and the angular expression:
<h1>{{"Hello, " + "Angular!}}</h1>
<!-- instead of -->
<h1> {{"Hello, " + "Angular!}} </h1>
...Because you have a space after the closing }} :-)

angularjs : ng-click event is not working

I am trying to append li element using jquery.the "li" element is appended successfully howerver ng-click event is not working. please help.
below is my code.
$(".language-list").append("<li><span ng-click='selectOperator(op)'><label for=checkbox" + $scope.allOperators[op].operator_id + " class=labeloperator" + ">" + $scope.allOperators[op].operator_name + "</label></div></span></li>");
On append you need compile the element.
It not good practice to do that in controller. Use directive for any DOM selection/manipulation.
Anyways here is example:
var elmnt = angular.element(/* ... */);
elmnt.append(
$compile(
"<li><span ng-click='selectOperator(op)'><label for=checkbox" + $scope.allOperators[op].operator_id + " class=labeloperator" + ">" + $scope.allOperators[op].operator_name + "</label></div></span></li>"
)($scope));
You must compile the dynamic HTML to do the work.
$(".language-list")
.append(
$compile(
"<li><span ng-click='selectOperator(op)'><label for=checkbox" +
$scope.allOperators[op].operator_id + " class=labeloperator" + ">" +
$scope.allOperators[op].operator_name + "</label></div></span></li>")
)($scope);
For more Information about $compile service

Resources