how is this 'search' statement working? [duplicate] - javascript

This question already has answers here:
What is the point of using labels in javascript (label: stuff here) outside switches?
(2 answers)
Closed 5 years ago.
I was reading a book and I am not able to find how this search: is working.
search:while (true){
n++;
for(let i=2;i<=Math.sqrt(n);i++){
if(n%i===0){
continue search;
}
}
Is it predefined in javascript, or what is it?

It's a label, and continue tells the loop to go back to the label.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue#Using_continue_with_a_label

Related

I need javascript/html assistance with making a textfield (not)readOnly [duplicate]

This question already has answers here:
remove readonly from input
(2 answers)
Closed 2 years ago.
I find myself at a loss. I am charged with the seemingly trivial task of making a text field (not) read only, if some condition is true. well, I have hit the wall.
I have tried various versions of the following:
if(someTextBox.enable==false){
someTextBox.enable=true;}
including
someTextBox.setAttribute("enable", true);
and even
someTextBox.setAttribute("readOnly", true);
I am using Chrome devtools, and can see various incarnations of null, including ignored if-clauses.
You can simply do:
document.getElementById("myText").readOnly = false;

How to read data between xml tags with attributes in javascript/ionic without using DOM/ActiveXObject? [duplicate]

This question already has answers here:
Parse XML using JavaScript [duplicate]
(2 answers)
Closed 5 years ago.
I simply need to extract some info between two tags, in this case, <wsse:BinarySecurityToken>
For example:
<wsse:BinarySecurityToken att1="abc" att2="cd3" att3="adfa">This is a text I need!!!===</wsse:BinarySecurityToken>
I tried
match = text.match(/<wsse:BinarySecurityToken[.*]>([^<]*)<\/wsse:BinarySecurityToken>/g)
does't work!
Or is there anything better than regex? I use angularJs 1
You want to do:
match = text.match(/<tag1.*>([^<]*)<\/tag1>/g)

Javascript - Remove certain character in an element [duplicate]

This question already has answers here:
Replace method doesn't work
(4 answers)
Closed 6 years ago.
If I have a input box with value 'jklmnop', how would I go about removing 'k' using javascript?
I was thinking something along the lines of:
<input type='text' id='letters' value='jklmnop'/>
<button onclick='removeK()'>Remove</button
Using this javascript:
function removeK() {
document.getElementById('letters').value.replace('k','');
}
Can anyone tell me why this doesn't work? And if so, what would I need to do to make it work?
Thanks :)
You aren't setting the value.
var l = document.getElementById('letters');
l.value = l.value.replace('k','');

Modify Javascript Variable with URL [duplicate]

This question already has answers here:
Get the values from the "GET" parameters (JavaScript) [duplicate]
(63 answers)
Closed 6 years ago.
Is it possible to change a javascript variable through the URL?
Here's an example of the code I'm trying to modify from a website. (www.example.com)
<script type="text/javascript">
var x = 0;
</script>
I want to change the variable x from 0 to 1.
I want to do this by appending something to the URL. I'm not sure about the syntax, but I think it may be something like this:
www.example.com#javascript: var=1;
Is it possible to change variable x by only modifying the URL?
EDIT:
The duplicate question doesn't tell me how (if it's possible) to change the variable through the URL. Please let me know if that's not the case.
Related Question:
https://security.stackexchange.com/questions/134240/modify-javascript-variable-with-url-exploit
you can use:
if(window.location.href.indexOf("your_link_to_check") > -1) {
var x = 1;
}

Why is "javascript:" prepended to onchange in this html code? [duplicate]

This question already has answers here:
What's the purpose (if any) of "javascript:" in event handler tags?
(10 answers)
Closed 7 years ago.
Recently I have seen the following HTML when viewing source code in Chrome:
<select class="menu_combo" onchange="javascript:myfunction()">
<!-- rest of code goes here -->
Why is the word javascript and a colon (:) added in front of myfunction()? I thought that onchange was a javascript event. If so, what is the need for this?
There is no need for it; it’s a mistake/misconception by the author. It still works because it’s a valid label, used properly with loops:
loop: while (true) {
while (true) {
break loop;
}
}

Categories