# How to pass a value rather than object ?

**URL:** https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351
**Category:** programming
**Created:** [January 7, 2022, 4:21am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351 "2022-01-07T04:21:23Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [January 7, 2022, 4:21am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/1 "2022-01-07T04:21:23Z")

</div>

main.js (sends a msg to renderer.js)

````auto
    console.log("2 main.js 'did-start-navigation' = " + url) **// this shows a value**
 win.webContents.send('Send-url', url) ;   
}) // 'did-start-navigation' ```

preload.js (receives message from main.js , them preload.js plugs message into id="url")
```ipcRenderer.on('Send-url', holdUrl => {
  document.getElementById("url").value = holdUrl;
  console.log('2 holdUrl = ' + holdUrl) **// this shows a value**
}) ```

index.html
``` <input id="url" type="url" value="https://google.com"/> ```

But what gets plugged into <input> is this: '[object Object]' 

How do I pass a value , not an object ?

Thanks
````

---

<div class="post-metadata">

### Author: ![radmo](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@radmo](https://forum.kirupa.com/u/radmo)
#### Post date: [January 7, 2022, 7:59am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/2 "2022-01-07T07:59:58Z")

</div>

At [quote=“vmars316, post:1, topic:650351”]  
`ipcRenderer.on(`  
[/quote] you are calling the arrow function. This arrow function is returning something which you are assigning to the “url” element. If this “holdUrl” is an object, then you should rather assing the “text” or “html” property instead. What is it returning in “holdUrl?”

I just thought that “holdUrl =\>” might have to be written as “(holdUrl) =\>”. I have ccome up against weird bugs related to arrow functions in the past. Try it and see if it works.

---

<div class="post-metadata">

### Author: ![aanne0851](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@aanne0851](https://forum.kirupa.com/u/aanne0851)
#### Post date: [January 7, 2022, 10:12am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/3 "2022-01-07T10:12:48Z")

</div>

Thank you for valuable information

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [January 7, 2022, 3:13pm UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/4 "2022-01-07T15:13:48Z")

</div>

Thanks radmo ,  
Sorry to say that didn’t work .  
This console.log:  
main.js  
view.webContents.on(‘will-navigate’, (event, url) =\> {  
console.log(" 1 main.js view.webContents.on( will-navigate = " + url)  
win.webContents.send(‘Send-url’, url) ;  
})  
shows url correctly.  
But when url gets to:  
preload.js  
ipcRenderer.on(‘Send-url’, url =\> {  
console.log('2 url = ’ + url)  
document.getElementById(“url”).value = url ;  
console.log('2 url = ’ + url)  
})  
it is an object , rather than the value of that object .  
BTW: for simplicity , I dropped holdUrl .  
Thanks for your help…  
[https://gist.github.com/58b504c9cd156eacb71dbfe4238a3066](https://gist.github.com/58b504c9cd156eacb71dbfe4238a3066)

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [January 8, 2022, 12:08am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/5 "2022-01-08T00:08:12Z")

</div>

TBH I don’t know anything about the framework your using but it seem your trying to mutate one of the function arguments then return it without `return`.

> [@vmars316](#):
>
> ````auto
> preload.js (receives message from main.js , them preload.js plugs message into id="url")
> ```ipcRenderer.on('Send-url', holdUrl => {
> document.getElementById("url").value = holdUrl;
> console.log('2 holdUrl = ' + holdUrl) **// this shows a value**
> }) ```
> 
> ````

When you call a function you can store its value to a variable e.g.

```auto
const myFunc = function(){return "this is a return value"}
let runFunction = myFunc()

```

so the variable `runFunction ` stores the `return` value of `myFunc()` after it has been run which is immediately

You can also do it another way with a global variable e.g.

```auto
var global = undefined
const myFunc = function(){ return global = 'another return value'}
myFunc()

```

So now `global` has been reassigned to the value of `myFunc()`

If its not a global variable you **cant** do this:

```auto
const func1 = function(value){ value = 6789}
const func2 = function(){
var randomVal = 12345
func1(randomVal);
console.log(randomVal) // logs out 12345 not 6789
}

```

You can however do this:

```auto
const func1 = function(value){ return value + 500000}
const func2 = function(){
var randomVal = 12345
randomVal = func1(randomVal);// reassign randomVal to return of func1
console.log(randomVal) // logs out 512,345 
}

```

This might be what your wanting to do:

```auto
var holdURL = undefined; //GLOBAL
ipcRenderer.on('Send-url', function(){
    let value = document.getElementById("url").value; // get value of input or option element with id "url"
    return holdURL = value; // reassign GLOBAL variable holdURL
}

```

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [January 8, 2022, 4:39pm UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/6 "2022-01-08T16:39:36Z")

</div>

Steve , Thanks for your detailed Reply .  
I dont want to return anything .  
I am merely trying to update

> [@vmars316](#):
>
> `<input id="url" type="url" value="https://google.com"/>`

with a new value , sent by , main.js  
When it is sent to preload.js is a variable , like “[http://vmars.us](http://vmars.us)”  
But when it is received by preload,js , it is now an [object Object] .  
Why did it get changed to an object ?  
What do I need to do to change it back to a variable ?  
[https://gist.github.com/58b504c9cd156eacb71dbfe4238a3066](https://gist.github.com/58b504c9cd156eacb71dbfe4238a3066)  
Thanks

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [January 8, 2022, 11:40pm UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/7 "2022-01-08T23:40:17Z")

</div>

ah my bad… I don’t know how it got changed to an `object` but that is usually the case with `events` or if you want to `return` more than one thing from a `function`.

I’d rename the argument to event just for clarity…

Just `console.log(event)` the event and work out what property is the `url`.  
Then either access the object or use destructuring in the arguments. e.g

```auto
ipcRenderer.on('Send-url', event => {
    console.log(event)// e.g {target: "someElement" , type: "click", url: "http://vmars.us"}
    let element = document.getElementById("url");
    element.value = event.url // access event object and update url input
})

```

or use object destructuring

```auto
// {url} = I only want the url property of the event object (first argument)
// {url = "fallback.com"} = if(event.url == undefined) event.url = 'fallback.com'
ipcRenderer.on('Send-url', ({url = 'fallback.com'}) => {
    let element = document.getElementById("url");
    element.value = url
})

```

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [January 13, 2022, 9:58pm UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/8 "2022-01-13T21:58:13Z")

</div>

Thanks for your help…

---

<div class="post-metadata">

### Author: ![Brackwom](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@Brackwom](https://forum.kirupa.com/u/Brackwom)
#### Post date: [February 18, 2022, 10:44am UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/9 "2022-02-18T10:44:56Z")

</div>

Thank you for sharing this useful knowledge.

---

<div class="post-metadata">

### Author: ![xembdlive123](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/xembdlive123/32/17715_2.png) [@xembdlive123](https://forum.kirupa.com/u/xembdlive123)
#### Post date: [May 21, 2022, 3:00pm UTC](https://forum.kirupa.com/t/how-to-pass-a-value-rather-than-object/650351/10 "2022-05-21T15:00:48Z")

</div>

Thank you sharing!
