how do i pass array from select html element component to two text components that have different values in...
I'm trying to get the price value from the select element after I've selected a value. e.g stock-description:"Numbers Invo Qt", Selling-Price:"100". But I've written the code below and when i run it i get this error Selling-Price returns "undefined".
So I would really appreciate it you could help me because I've search the internet the whole day looking for help.
import React, { Component } from 'react';
import _ from 'lodash';
const ITEMS = [
{ name: 'initial', text: 'Select Items', value: '' },
{ name: 'centos', text: 'Invo qt', value: 'Numbers Invo qt', price: "100" },
{ name: 'ubuntu', text: 'Invo xp', value: 'Numbers Invo xp', price: "180" },
]
const SelectComponent = (props) => (
<select name={props.name}
onChange={props.handleSelect}
>
{_.map(props.items, (item, i) =>
<Option
key={i}
name={item.name}
value={item.value}
text={item.text}
price={item.price}
handleSelect={props.handleSelect}
/>
)}
</select>
);
const Option = (props) => (
<option
value={props.value}
>{props.text}</option>
)
export default class CustomerComboBox extends Component {
constructor() {
super()
this.state = {
selected: '',
selected_Price: ''
}
this.handleSelect = this.handleSelect.bind(this);
}
handleSelect(e) {
e.preventDefault();
//console.log(e.target);
this.setState({
selected: e.target.value,
selected_Price: e.target.price,
})
document.getElementById('stock-description').value = e.target.value;
document.getElementById('stock-price').value = e.target.price;
}
render() {
return (
<div>
<div>
<SelectComponent
name="testSelect"
items={ITEMS}
price={ITEMS.price}
handleSelect={this.handleSelect}
/>
</div>
<p>Stock Description</p>
<input id='stock-description' placeholder='Item Description'></input>
<p>Stock Price</p>
<input id='stock-price' placeholder='Selling Price'></input>
</div>
);
}
}
javascript reactjs jsx
add a comment |
I'm trying to get the price value from the select element after I've selected a value. e.g stock-description:"Numbers Invo Qt", Selling-Price:"100". But I've written the code below and when i run it i get this error Selling-Price returns "undefined".
So I would really appreciate it you could help me because I've search the internet the whole day looking for help.
import React, { Component } from 'react';
import _ from 'lodash';
const ITEMS = [
{ name: 'initial', text: 'Select Items', value: '' },
{ name: 'centos', text: 'Invo qt', value: 'Numbers Invo qt', price: "100" },
{ name: 'ubuntu', text: 'Invo xp', value: 'Numbers Invo xp', price: "180" },
]
const SelectComponent = (props) => (
<select name={props.name}
onChange={props.handleSelect}
>
{_.map(props.items, (item, i) =>
<Option
key={i}
name={item.name}
value={item.value}
text={item.text}
price={item.price}
handleSelect={props.handleSelect}
/>
)}
</select>
);
const Option = (props) => (
<option
value={props.value}
>{props.text}</option>
)
export default class CustomerComboBox extends Component {
constructor() {
super()
this.state = {
selected: '',
selected_Price: ''
}
this.handleSelect = this.handleSelect.bind(this);
}
handleSelect(e) {
e.preventDefault();
//console.log(e.target);
this.setState({
selected: e.target.value,
selected_Price: e.target.price,
})
document.getElementById('stock-description').value = e.target.value;
document.getElementById('stock-price').value = e.target.price;
}
render() {
return (
<div>
<div>
<SelectComponent
name="testSelect"
items={ITEMS}
price={ITEMS.price}
handleSelect={this.handleSelect}
/>
</div>
<p>Stock Description</p>
<input id='stock-description' placeholder='Item Description'></input>
<p>Stock Price</p>
<input id='stock-price' placeholder='Selling Price'></input>
</div>
);
}
}
javascript reactjs jsx
add a comment |
I'm trying to get the price value from the select element after I've selected a value. e.g stock-description:"Numbers Invo Qt", Selling-Price:"100". But I've written the code below and when i run it i get this error Selling-Price returns "undefined".
So I would really appreciate it you could help me because I've search the internet the whole day looking for help.
import React, { Component } from 'react';
import _ from 'lodash';
const ITEMS = [
{ name: 'initial', text: 'Select Items', value: '' },
{ name: 'centos', text: 'Invo qt', value: 'Numbers Invo qt', price: "100" },
{ name: 'ubuntu', text: 'Invo xp', value: 'Numbers Invo xp', price: "180" },
]
const SelectComponent = (props) => (
<select name={props.name}
onChange={props.handleSelect}
>
{_.map(props.items, (item, i) =>
<Option
key={i}
name={item.name}
value={item.value}
text={item.text}
price={item.price}
handleSelect={props.handleSelect}
/>
)}
</select>
);
const Option = (props) => (
<option
value={props.value}
>{props.text}</option>
)
export default class CustomerComboBox extends Component {
constructor() {
super()
this.state = {
selected: '',
selected_Price: ''
}
this.handleSelect = this.handleSelect.bind(this);
}
handleSelect(e) {
e.preventDefault();
//console.log(e.target);
this.setState({
selected: e.target.value,
selected_Price: e.target.price,
})
document.getElementById('stock-description').value = e.target.value;
document.getElementById('stock-price').value = e.target.price;
}
render() {
return (
<div>
<div>
<SelectComponent
name="testSelect"
items={ITEMS}
price={ITEMS.price}
handleSelect={this.handleSelect}
/>
</div>
<p>Stock Description</p>
<input id='stock-description' placeholder='Item Description'></input>
<p>Stock Price</p>
<input id='stock-price' placeholder='Selling Price'></input>
</div>
);
}
}
javascript reactjs jsx
I'm trying to get the price value from the select element after I've selected a value. e.g stock-description:"Numbers Invo Qt", Selling-Price:"100". But I've written the code below and when i run it i get this error Selling-Price returns "undefined".
So I would really appreciate it you could help me because I've search the internet the whole day looking for help.
import React, { Component } from 'react';
import _ from 'lodash';
const ITEMS = [
{ name: 'initial', text: 'Select Items', value: '' },
{ name: 'centos', text: 'Invo qt', value: 'Numbers Invo qt', price: "100" },
{ name: 'ubuntu', text: 'Invo xp', value: 'Numbers Invo xp', price: "180" },
]
const SelectComponent = (props) => (
<select name={props.name}
onChange={props.handleSelect}
>
{_.map(props.items, (item, i) =>
<Option
key={i}
name={item.name}
value={item.value}
text={item.text}
price={item.price}
handleSelect={props.handleSelect}
/>
)}
</select>
);
const Option = (props) => (
<option
value={props.value}
>{props.text}</option>
)
export default class CustomerComboBox extends Component {
constructor() {
super()
this.state = {
selected: '',
selected_Price: ''
}
this.handleSelect = this.handleSelect.bind(this);
}
handleSelect(e) {
e.preventDefault();
//console.log(e.target);
this.setState({
selected: e.target.value,
selected_Price: e.target.price,
})
document.getElementById('stock-description').value = e.target.value;
document.getElementById('stock-price').value = e.target.price;
}
render() {
return (
<div>
<div>
<SelectComponent
name="testSelect"
items={ITEMS}
price={ITEMS.price}
handleSelect={this.handleSelect}
/>
</div>
<p>Stock Description</p>
<input id='stock-description' placeholder='Item Description'></input>
<p>Stock Price</p>
<input id='stock-price' placeholder='Selling Price'></input>
</div>
);
}
}
javascript reactjs jsx
javascript reactjs jsx
edited Nov 25 '18 at 20:38
Dacre Denny
13.8k41233
13.8k41233
asked Nov 25 '18 at 20:37
Tony NgomanaTony Ngomana
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Price won't get passed like that. My advice would be, to onChange pass the entire object.
onChange={ (e) => props.handleSelect(props.items[e.target.value]) }
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing theonChange
method, to pass tohandleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)
– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471715%2fhow-do-i-pass-array-from-select-html-element-component-to-two-text-components-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Price won't get passed like that. My advice would be, to onChange pass the entire object.
onChange={ (e) => props.handleSelect(props.items[e.target.value]) }
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing theonChange
method, to pass tohandleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)
– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
add a comment |
Price won't get passed like that. My advice would be, to onChange pass the entire object.
onChange={ (e) => props.handleSelect(props.items[e.target.value]) }
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing theonChange
method, to pass tohandleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)
– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
add a comment |
Price won't get passed like that. My advice would be, to onChange pass the entire object.
onChange={ (e) => props.handleSelect(props.items[e.target.value]) }
Price won't get passed like that. My advice would be, to onChange pass the entire object.
onChange={ (e) => props.handleSelect(props.items[e.target.value]) }
answered Nov 25 '18 at 20:43
AdamAdam
1,84911726
1,84911726
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing theonChange
method, to pass tohandleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)
– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
add a comment |
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing theonChange
method, to pass tohandleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)
– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
I tried to pass the entire object but the values aren't being return as well
– Tony Ngomana
Nov 26 '18 at 5:34
Did you pass it in a way I am suggesting? I am replacing the
onChange
method, to pass to handleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)– Adam
Nov 26 '18 at 6:44
Did you pass it in a way I am suggesting? I am replacing the
onChange
method, to pass to handleSelect
only one item from array, using id that has been selected. Code is not pretty, but I am quite confident this would work well :)– Adam
Nov 26 '18 at 6:44
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
Yes i did i later get this error "TypeError: e is undefined"
– Tony Ngomana
Nov 26 '18 at 10:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471715%2fhow-do-i-pass-array-from-select-html-element-component-to-two-text-components-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown