Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for hkotsubo
| Type | On... | Excerpt | Status | Date |
|---|---|---|---|---|
| Comment | Post #285130 |
@#36363 "send data" means making a http request, using fetch with POST method (there's an example in the [docs](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options)). And you can use [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormDat... (more) |
— | almost 5 years ago |
| Comment | Post #285130 |
@#36363 Then I suggest you to edit the question and add this information there.
But anyway, if you want to execute behavior.php, you'll have to send data to it (which is basically what I described above) (more) |
— | almost 5 years ago |
| Comment | Post #285148 |
Regarding string handling, [this post](https://software.codidact.com/posts/284849) might be helpful (more) |
— | almost 5 years ago |
| Comment | Post #285130 |
After the last edit it's still unclear what you mean by "*apply backend behavior*".
Do you have a `form action="URL A"` and want to send all its data to URL B using JavaScript? (more) |
— | almost 5 years ago |
| Edit | Post #285135 |
Post edited: Missed one extra backtick in code block, now it should be correct |
— | almost 5 years ago |
| Suggested Edit | Post #285135 |
Suggested edit: Missed one extra backtick in code block, now it should be correct (more) |
helpful | almost 5 years ago |
| Edit | Post #285135 |
Post edited: Better title, fix code block |
— | almost 5 years ago |
| Suggested Edit | Post #285135 |
Suggested edit: Better title, fix code block (more) |
helpful | almost 5 years ago |
| Comment | Post #285130 |
Not sure if that's what you need, but if I understood correctly, it'd be something like this:
```javascript
let form = // get the form somehow (for example, with querySelector)
form.addEventListener('submit', function(e) {
e.preventDefault(); // don't submit the form
fetch('backend.url... (more) |
— | almost 5 years ago |
| Edit | Post #285104 |
Post edited: Remove clutter and try to come up with a better title |
— | almost 5 years ago |
| Edit | Post #285105 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #285105 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #285105 | Initial revision | — | almost 5 years ago |
| Answer | — |
A: What does a variable followed by parentheses ("ptr()") mean? `void (ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take an arbitrary number of parameters (that's what the empty parentheses defines). Then, `ptr = PrintHello` assigns the `PrintHello` function to th... (more) |
— | almost 5 years ago |
| Suggested Edit | Post #285104 |
Suggested edit: Remove clutter and try to come up with a better title (more) |
helpful | almost 5 years ago |
| Comment | Post #285019 |
@#36363 Could you add a link to the website, so we can at least check the HTML and try to see what the problem is? Because your code *should* work.
Just double checking the basic stuff: what does `document.querySelector("#example")` return? When you run your code, does any error message appear i... (more) |
— | almost 5 years ago |
| Comment | Post #285019 |
Maybe - and that's a *wild guess* - the JavaScript code is running before the HTML is loaded, and it can't find the input field. Check if the `script` tag is before the form and change it to be after. Or add an event listener to run after the page is loaded:
```javascript
document.addEventLis... (more) |
— | almost 5 years ago |
| Comment | Post #284981 |
@#36363 I've made a simple test:
```javascript
var old = document;
document.write('abc');
console.log(old === document); // true
```
Which means that the document didn't change (only its child nodes). Another test to check if child nodes changed:
```javascript
// keep reference to ori... (more) |
— | almost 5 years ago |
| Comment | Post #284981 |
@#36363 My understanding is that the document itself is not removed, only its child nodes. But I'll make more tests as soon as I can (more) |
— | almost 5 years ago |
| Edit | Post #284981 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284981 | Initial revision | — | almost 5 years ago |
| Answer | — |
A: document.open() and the DOM tree of the loaded (closed) browser window on which it works At the documetation you linked, if you click on "which will clear the document", it'll go to the documentation for `document.open`, and that page says in the beginning: > All existing nodes are removed from the document. And once removed, you can't retrieve them. Making a test in this pa... (more) |
— | almost 5 years ago |
| Edit | Post #284941 |
Post edited: Typo |
— | almost 5 years ago |
| Edit | Post #284941 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284941 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284941 | Initial revision | — | almost 5 years ago |
| Answer | — |
A: Understanding createTreeWalker method in the context of replacing strings (or parts of them) > How does storing replaced strings in the `node` variable makes a change in the text appearing to the end user? In your case, you're changing the `textContent` property. When accessed, it returns the text content of a node, concatenated with the text content of its descendants, and changing i... (more) |
— | almost 5 years ago |
| Edit | Post #284928 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284928 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284928 | Initial revision | — | almost 5 years ago |
| Question | — |
Code block in comments is highlighted only when viewed in the thread's link Code blocks inside comments are hightlighted only if I'm on the comment's thread page. If I view it on the post itself (after expanding the respective thread), it's not highlighted. Example: in this post I clicked on the comment thread to expand it, and the code block is not highlighted: ... (more) |
— | almost 5 years ago |
| Comment | Post #284911 |
@#53305 To add a little bit more pedantry, the filter predicate doesn't have to be exactly a boolean, because in Python [any object can be tested for truth value](https://docs.python.org/3/library/stdtypes.html#truth-value-testing). Which means I can do this:
```python
values = ['abc', '', []... (more) |
— | almost 5 years ago |
| Comment | Post #284853 |
@#36363 You're welcome, glad to help! (more) |
— | almost 5 years ago |
| Edit | Post #284842 |
Post edited: Change title to make more clear what the question is about |
— | almost 5 years ago |
| Suggested Edit | Post #284842 |
Suggested edit: Change title to make more clear what the question is about (more) |
helpful | almost 5 years ago |
| Edit | Post #284853 |
Post edited: some "future-proof" stuff |
— | almost 5 years ago |
| Edit | Post #284853 |
Post edited: some "future-proof" stuff |
— | almost 5 years ago |
| Edit | Post #284853 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284853 | Initial revision | — | almost 5 years ago |
| Answer | — |
A: Change font-family with JavaScript To do that, you could change the selector from `body` to ``, as the other answer said. By selecting only `body`, it won't change child elements that has defined a more specific rule, and that's why you need to set the style for all of them. But there are some corner cases that I think it's wor... (more) |
— | almost 5 years ago |
| Comment | Post #284806 |
@#54649 I've made [this test](https://ideone.com/EkRHga) and surprisingly using string slices is faster than doing the math. Try to change the algorithm and see if it makes some difference (more) |
— | almost 5 years ago |
| Comment | Post #284806 |
@#54649 For quick performance tests you can use the [`timeit` module](https://docs.python.org/3/library/timeit.html). I've made [a simple example](https://ideone.com/xjEhaR), and creating the function inside the loop was about 50%~60% slower. (more) |
— | almost 5 years ago |
| Comment | Post #284806 |
You're creating the function inside the loop, so for every iteration a new function is created. But that's not needed at all, creating it just once outside the loop is enough.
Not sure how much it'll improve performance, but it certainly won't make it worse (more) |
— | almost 5 years ago |
| Edit | Post #284803 |
Post edited: Improve title, make text more concise, add tags |
— | almost 5 years ago |
| Edit | Post #284804 |
Post edited: |
— | almost 5 years ago |
| Suggested Edit | Post #284803 |
Suggested edit: Improve title, make text more concise, add tags (more) |
helpful | almost 5 years ago |
| Edit | Post #284804 | Initial revision | — | almost 5 years ago |
| Answer | — |
A: Separate digits of a number in groups with different sizes Before we start, I'd like to be a little bit pedantic regarding `00002451018` being a number. When we talk about numeric types/values, the zeroes at the beginning are irrelevant: `2`, `02` and `000002` all refer to the number two. The numeric value is `2`, and only the representation - the way... (more) |
— | almost 5 years ago |
| Edit | Post #284710 |
Post edited: |
— | almost 5 years ago |
| Edit | Post #284710 |
Post edited: |
— | almost 5 years ago |
