deactivate event after I clicked in the specific table cell
I am using this code to replace a value inside a td cell and to pop up a select input.
$(document).one('click',"#editlanguageinline", function (e) {
$(this).html('<select><option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option></select>');
});
I would like to create an inline edit for this table row/cell. So the user should be able to select a value for every new row in this column and after selecting it, a ajax event calls the php file where the new value is updated. But if I want to choose a new value in the dropdown menu, the css event is activated again. So the replacement event is fired again and I can not choose a value. How can I avoid this?
I tried the command .one() but than all other rows do not really activate the event because than it is really only activated once. It should be deactivated for the cell that I currently clicked so I can choose a value.
thank you in advance for any help.
jquery css onclick
add a comment |
I am using this code to replace a value inside a td cell and to pop up a select input.
$(document).one('click',"#editlanguageinline", function (e) {
$(this).html('<select><option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option></select>');
});
I would like to create an inline edit for this table row/cell. So the user should be able to select a value for every new row in this column and after selecting it, a ajax event calls the php file where the new value is updated. But if I want to choose a new value in the dropdown menu, the css event is activated again. So the replacement event is fired again and I can not choose a value. How can I avoid this?
I tried the command .one() but than all other rows do not really activate the event because than it is really only activated once. It should be deactivated for the cell that I currently clicked so I can choose a value.
thank you in advance for any help.
jquery css onclick
Please click edit then snippet editor[<>]
and creater a Minimal, Complete, and Verifiable example
– mplungjan
Nov 26 '18 at 10:40
add a comment |
I am using this code to replace a value inside a td cell and to pop up a select input.
$(document).one('click',"#editlanguageinline", function (e) {
$(this).html('<select><option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option></select>');
});
I would like to create an inline edit for this table row/cell. So the user should be able to select a value for every new row in this column and after selecting it, a ajax event calls the php file where the new value is updated. But if I want to choose a new value in the dropdown menu, the css event is activated again. So the replacement event is fired again and I can not choose a value. How can I avoid this?
I tried the command .one() but than all other rows do not really activate the event because than it is really only activated once. It should be deactivated for the cell that I currently clicked so I can choose a value.
thank you in advance for any help.
jquery css onclick
I am using this code to replace a value inside a td cell and to pop up a select input.
$(document).one('click',"#editlanguageinline", function (e) {
$(this).html('<select><option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option></select>');
});
I would like to create an inline edit for this table row/cell. So the user should be able to select a value for every new row in this column and after selecting it, a ajax event calls the php file where the new value is updated. But if I want to choose a new value in the dropdown menu, the css event is activated again. So the replacement event is fired again and I can not choose a value. How can I avoid this?
I tried the command .one() but than all other rows do not really activate the event because than it is really only activated once. It should be deactivated for the cell that I currently clicked so I can choose a value.
thank you in advance for any help.
jquery css onclick
jquery css onclick
asked Nov 26 '18 at 10:36
hillcodehillcode
576
576
Please click edit then snippet editor[<>]
and creater a Minimal, Complete, and Verifiable example
– mplungjan
Nov 26 '18 at 10:40
add a comment |
Please click edit then snippet editor[<>]
and creater a Minimal, Complete, and Verifiable example
– mplungjan
Nov 26 '18 at 10:40
Please click edit then snippet editor
[<>]
and creater a Minimal, Complete, and Verifiable example– mplungjan
Nov 26 '18 at 10:40
Please click edit then snippet editor
[<>]
and creater a Minimal, Complete, and Verifiable example– mplungjan
Nov 26 '18 at 10:40
add a comment |
2 Answers
2
active
oldest
votes
Try This :
$('#table').on('click','#editlanguageinline', function (e) {
if ($(this).find("select").length==0) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
}
});
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
|
show 6 more comments
I created sample fiddle with your example and my modifications. Key thing is that you need to bind your event to all 'td's only. And in this case select change will not fire this change again.
$('#table').on('click','td', function (e) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
});
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
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%2f53479276%2fdeactivate-event-after-i-clicked-in-the-specific-table-cell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try This :
$('#table').on('click','#editlanguageinline', function (e) {
if ($(this).find("select").length==0) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
}
});
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
|
show 6 more comments
Try This :
$('#table').on('click','#editlanguageinline', function (e) {
if ($(this).find("select").length==0) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
}
});
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
|
show 6 more comments
Try This :
$('#table').on('click','#editlanguageinline', function (e) {
if ($(this).find("select").length==0) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
}
});
Try This :
$('#table').on('click','#editlanguageinline', function (e) {
if ($(this).find("select").length==0) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
}
});
edited Nov 28 '18 at 17:35
answered Nov 26 '18 at 11:37
mkanemkane
21438
21438
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
|
show 6 more comments
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
this checks the current value if it is not "volvo" but it can be volvo as well. Do you have any other solution?
– hillcode
Nov 26 '18 at 12:10
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
No that is just checking to see if the html was already generated for that node. The code supplied works for other rows also... Try it..
– mkane
Nov 26 '18 at 12:13
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
works great! thank you very much! so "volvo" should be always the value of the first select option?
– hillcode
Nov 26 '18 at 13:27
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
No I am just looking for the existence of the string volvo in the html to see of the <select> html was previously generated. You could just test to see if there is a select present rather than the volvo string. You could even just add some logic to the select html and give it an id and then test to see of the element exists on subsequent clicks.. The includes (...) is simply looking into the html text for the element..
– mkane
Nov 26 '18 at 14:25
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
I updated the answer to show how to test for existence of the created select by it's id too..
– mkane
Nov 26 '18 at 14:46
|
show 6 more comments
I created sample fiddle with your example and my modifications. Key thing is that you need to bind your event to all 'td's only. And in this case select change will not fire this change again.
$('#table').on('click','td', function (e) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
});
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
add a comment |
I created sample fiddle with your example and my modifications. Key thing is that you need to bind your event to all 'td's only. And in this case select change will not fire this change again.
$('#table').on('click','td', function (e) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
});
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
add a comment |
I created sample fiddle with your example and my modifications. Key thing is that you need to bind your event to all 'td's only. And in this case select change will not fire this change again.
$('#table').on('click','td', function (e) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
});
I created sample fiddle with your example and my modifications. Key thing is that you need to bind your event to all 'td's only. And in this case select change will not fire this change again.
$('#table').on('click','td', function (e) {
$(this).html('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');
});
answered Nov 26 '18 at 10:50
dganencodganenco
2217
2217
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
add a comment |
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
thank you! but it should not be fired on every column ... only the column where the td has the id #editlanguageinline. how can I achieve this?
– hillcode
Nov 26 '18 at 11:29
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). w3schools.com/Html/html_id.asp
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
Use should use 'class' instead. I updated my fiddle with working class example jsfiddle.net/Dganenco/jdv8ypx3
– dganenco
Nov 26 '18 at 12:20
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%2f53479276%2fdeactivate-event-after-i-clicked-in-the-specific-table-cell%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
Please click edit then snippet editor
[<>]
and creater a Minimal, Complete, and Verifiable example– mplungjan
Nov 26 '18 at 10:40