# How to accessing defaults variable in oneditprepare

**URL:** <https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623>\
**Category:** Developing Nodes\
**Created:** [13 January 2023 05:11 UTC](https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623 "2023-01-13T05:11:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![syedhannan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syedhannan/32/72932_2.png) [@syedhannan](https://discourse.nodered.org/u/syedhannan)\
**Post date:** [13 January 2023 05:11 UTC](https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623/1 "2023-01-13T05:11:37Z")

</div>

I want to access a variable defined in my html file in defaults inside my **oneditprepare** function.

```auto
  RED.nodes.registerType("myNode", {
    category: "Custom",
    color: "#07950D",
    defaults: {
      name: { value: "" },
      timezone: { value: "" }, //accessing this in oneditprepare
    },
....
}

```

I am not sure how I can access it.

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [13 January 2023 07:59 UTC](https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623/2 "2023-01-13T07:59:46Z")

</div>

Place a `debugger` statement into your oneditprepare and then look around in the browser's debugger 😉  
It's something like `this._def.defaults`. Note that these are the defaults, not the current value. To access the "currently saved" value it's just `this.<variable>`. If you want the current unsaved value then you have to go chase it down in the DOM input element. If you find this confusing and unwieldy: welcome to the club!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 January 2023 10:47 UTC](https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623/3 "2023-01-13T10:47:27Z")

</div>

oneditprepare inherits `this`, so `this.timezone` gives you access. Of course, the use of `this` must be treated carefully since going into a function - such as a jQuery callback function, changes what `this` is. So it is common to create a reference to the "correct" `this` early in the oneditprepare function. If you are calling your own functions, you can, of course, force `this` to be the correct one.

For myself, I never do inline code for `oneditprepare`, I always do this: `oneditprepare: function() { onEditPrepare(this) },`. Then my `onEditPrepare` function is defined as: `function onEditPrepare(node) { ... }`. I could have have used `oneditprepare: function() { onEditPrepare.bind(this) },` to force my function to have the correct `this` but I find it easier to just pass the reference onto `node` as it reduces confusion in my tiny brain.

To TVE's point about DOM values. The easiest thing is to assume that `this.timezone` contains a value that was the _last_ user input, not the _current_ input. So `$('#node-input-timezone').val()` will (mostly - except for things like select drop-down's) give you the current input.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 January 2023 10:48 UTC](https://discourse.nodered.org/t/how-to-accessing-defaults-variable-in-oneditprepare/73623/4 "2023-01-27T10:48:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
