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;
Related
This question already has answers here:
Set anonymous/dynamic functions to Menu
(3 answers)
Increment Cell value by one by clicking
(3 answers)
button click is only working on Windows & not working on Android mobile sheet
(2 answers)
Closed 2 years ago.
I need to do the same operations on different cells and I am trying to write a generic script. I give a trivial example that explains my problem below.
Let's say that I want to click on a button and decrease the value of the cell A1 by 1. That's straightforward. I define the following function
function dec_cell_def(){
var cell = fr = SpreadsheetApp.getActiveSheet().getRange("A1")
cell.setValue(cell.getValue() - 1)
}
Then assign the "script" dec_cell_def to any button and I am done.
Let's say now, that I want to do this for many different cells. I could of course write a function for each one, but this is hardly a solution. So I thought the following would work. I define the function cell_dec that take as an argument the label of a cell and returns a function that decreases the value of the cell:
function dec_cell(label){
() => {
var cell = fr = SpreadsheetApp.getActiveSheet().getRange(label)
cell.setValue(cell.getValue() - 1)
}
}
However when I assign the "script" dec_cell("A1") to a button, I am told that the script does not exist. What is the proper way to do that?
PS. I know that I can get the selected cell and act on it, but I would like to have a fixed target for my function.
Edit: I meant that I want to do this for few cells but not all at once. I would like to create a button for each cell and I would like to avoid copy-pasting the same code. I think that none of the suggested questions answer that.
This question already has answers here:
How can I get the data-id attribute?
(16 answers)
Closed 6 years ago.
HTML snippet:
<input title="List" data-id="1698481">
In IE 11 console, I've been trying various commands, and everything without a hyphen comes back correctly until I hit "data-id."
document.getElementsByTagName("input")[0].title
"List"
document.getElementsByTagName("input")[0].data-id
'id' is undefined
As per other threads on this subject, I tried other syntaxes (camel case, etc.), but I still can't get it to return any value
document.getElementsByTagName("input")[0].dataId
undefined
document.getElementsByTagName("input")[0].["data-id"]
Expected identifier
document.getElementsByTagName("input")[0].['data-id']
Expected identifier
Any assistance would be appreciated.
Use .getAttribute():
document.getElementsByTagName("input")[0].getAttribute("data-id")
The data-* attributes are special:
document.getElementsByTagName("input")[0].dataset.id
data-* attributes are converted from hyphens to camelCasing, so a data-test-attribute="test" would be equivalent to:
htmlElement.dataset.testAttribute; // test
For more information, see the MDN on dataset.
This question already has answers here:
style.display='none' doesn't work on option tags in chrome, but it does in firefox
(8 answers)
Closed 8 years ago.
Let me start off saying I hate IE.
I have a bit of code running to hide options in a select tag and then narrow them down and only show the narrowed down options. This works perfectly everywhere, except I.E. and I'm not really sure why.
My code looks something like this...
$("select[name='FormId']").prop("disabled", false);
$(".modalContent select[name='FormId'] option").hide();
var formIds = this.model.collection.models.map(function ( model ) {
return model.attributes.Form.attributes.Id
});
formIds.forEach(function ( formId ) {
$(".modalContent select[name='FormId'] option[value='"+ formId +"']").show();
});
Any help would be much appreciated!
this.model.collection.models is a plain array, so you'd need ES5 for map to work on it. just use this.model.collection.map which will use the safe one from underscore
This question already has answers here:
Changing input value while still allowing the user to type
(2 answers)
Closed 9 years ago.
If the user types:
my name is jackson5 model number 5g1 |nR%1b and I would 644 like to say 55 hello to all the tags of html in the world.
I'd like to replace the 55 hello with 55hello while they continue to type with no hiccups or interuptions to the input box.
here is my code so far. I have the regex statement in there but not sure how to replace the space between 55 hello so that it becomes 55hello.
<script type="text/javascript">
function isValid(strQuery){
var regStatement =/[0-9]+ hello/;
if (regStatement.test(strQuery.value)) {
strQuery.value = strQuery.value.replace("$2","");
}
}
</script>
<input type="text" id="wtf" name="search_query" onkeyup="isValid(this);" />
try this
function isValid(strQuery){
strQuery.value = strQuery.value.replace(/((\d+)\s+)(?=hello)/,"$2");
}
you don't need to test it first, if the string doesn't match, it won't replace anything.
I don't have enough reputation to post comments, so I will have to resort to an 'answer' -- be careful with this approach. I've tested my solution and also that posted by #leonhart above (his is much better, so I will not bother posting mine). What both have in common is that both cause TWO calls to isValid, in case if your input box has a history of similar inputs, and starts to provide suggestions (didn't occur in Chrome, but did in Firefox). Not sure what's causing it, but, apparently, either the event handler is registered twice, or something along those lines.. good luck figuring that out! Or maybe someone else here can explain the cause... and the workaround =)
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
how can i validate a url in javascript using regular expression
I want to validate whether user input a valid internet adress like
www.hotmail.com
http://www.abc.com.pk
Here's the js function:
function validateString(regexPattern, testString) {
var regexObj = new RegExp(regexPattern);
return regexObj.test(testString);
}
Finding the regex for URLs is just a matter of typing it in google. Here's a good one I've used before.