Jquery copy form inputs with keyupIs there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
Was Constantine The Great a Nicene Christian?
Horizontal alignment of matrix in an array by using llap and phantom
Issues with the new Sitecore Support portal
Threatening to discontinue a service for a client
Does Estonia have discount supermarket chains like Aldi and Lidl?
How to pass Collection of exceptions as a root cause?
Please help me cook :(
Help me pair my socks
Why are Trump's handwritten notes being focused on in the news?
Why is it ethical for Ambassador Sondland to have been given an ambassadorship for campaign contributions?
Why does the Eurofighter Typhoon pitch up on brake release?
Miniseries in post-rapture US with good/evil conflict
What are the units of the product of two signals?
How to save custom label as parameter for a custom entity_reference field widget?
Is Fox News not classified as a news channel?
How can the mechanism of electrons in an atom be explained?
Did any of the Space Shuttles land through rain or rainclouds?
Why does E7 sharp 9 have a G?
How can I speed up secure erasing of a disk?
Do one quarter of Swedes named 'Ali' have a criminal record?
Pointlessly recurse down the alphabet
Why would a berry have a slow-acting poison?
Why I am not getting True when testing equation?
What is the largest piece of space debris volumetrically?
Jquery copy form inputs with keyup
Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
Solved Needed to use the val instead of text. My mistake!
What is the difference when copying a form field to another form field vs copying a form field to a span id?
I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.
Using Jquery keyup
Can anyone enlighten me?
Heres a Demo
Thanks in advance
<input type="text" name="Quantity" value="100" id="quantity2" />
<input type="text" name="Quantity" id="quantity_img2" />
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").text(value);
).keyup();
jquery forms
add a comment
|
Solved Needed to use the val instead of text. My mistake!
What is the difference when copying a form field to another form field vs copying a form field to a span id?
I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.
Using Jquery keyup
Can anyone enlighten me?
Heres a Demo
Thanks in advance
<input type="text" name="Quantity" value="100" id="quantity2" />
<input type="text" name="Quantity" id="quantity_img2" />
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").text(value);
).keyup();
jquery forms
add a comment
|
Solved Needed to use the val instead of text. My mistake!
What is the difference when copying a form field to another form field vs copying a form field to a span id?
I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.
Using Jquery keyup
Can anyone enlighten me?
Heres a Demo
Thanks in advance
<input type="text" name="Quantity" value="100" id="quantity2" />
<input type="text" name="Quantity" id="quantity_img2" />
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").text(value);
).keyup();
jquery forms
Solved Needed to use the val instead of text. My mistake!
What is the difference when copying a form field to another form field vs copying a form field to a span id?
I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.
Using Jquery keyup
Can anyone enlighten me?
Heres a Demo
Thanks in advance
<input type="text" name="Quantity" value="100" id="quantity2" />
<input type="text" name="Quantity" id="quantity_img2" />
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").text(value);
).keyup();
jquery forms
jquery forms
edited Jun 4 '12 at 16:35
cantaffordretail
asked Jun 4 '12 at 16:30
cantaffordretailcantaffordretail
1,2763 gold badges22 silver badges42 bronze badges
1,2763 gold badges22 silver badges42 bronze badges
add a comment
|
add a comment
|
4 Answers
4
active
oldest
votes
To set the value of textbox element use val()
method instead of text()
.
Working demo http://jsfiddle.net/LnDYA/20/
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
add a comment
|
$("#quantity_img2").text(value);
should be
$("#quantity_img2").val(value);
DEMO
Why this happen
Because #quantity_img2
is an input field
, a form
element and to set value to input
field require .val()
method.
So your code should look like
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value); // not .text()
).keyup();
add a comment
|
Use .val()
in place of .text()
like this
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value);
).keyup();
Working fiddle
add a comment
|
I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:
$.fn.val2 = function (newVal)
// Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
// http://learn.jquery.com/plugins/basic-plugin-creation/
// use, get mode: var val = $("#" + id).val2();
// use, set mode: $("#" + id).val2("fred");
if (this !== undefined)
// newVal indicates set vs get mode
if (newVal === undefined)
var ret = "";
if (this.attr("value") === undefined && this.prop("value") === undefined)
ret = this.text(); // this is a span
else
ret = this.val(); // this would be an input
return ret;
else
if (this.attr("value") === undefined && this.prop("value") === undefined)
this.text(newVal); // this is a span
else
this.val(newVal); // this would be an input
;
Usage Examples:
Get mode:
var txt = $("#MySpan").val2();
var txt = $("#MyInput").val2();
Set mode:
$("#MySpan").val2("fred");
$("#MyInput").val2("fred");
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/4.0/"u003ecc by-sa 4.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%2f10884730%2fjquery-copy-form-inputs-with-keyup%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
To set the value of textbox element use val()
method instead of text()
.
Working demo http://jsfiddle.net/LnDYA/20/
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
add a comment
|
To set the value of textbox element use val()
method instead of text()
.
Working demo http://jsfiddle.net/LnDYA/20/
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
add a comment
|
To set the value of textbox element use val()
method instead of text()
.
Working demo http://jsfiddle.net/LnDYA/20/
To set the value of textbox element use val()
method instead of text()
.
Working demo http://jsfiddle.net/LnDYA/20/
answered Jun 4 '12 at 16:31
ShankarSangoliShankarSangoli
64.8k11 gold badges78 silver badges119 bronze badges
64.8k11 gold badges78 silver badges119 bronze badges
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
add a comment
|
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
Thanks this is this answer
– cantaffordretail
Jun 4 '12 at 16:33
add a comment
|
$("#quantity_img2").text(value);
should be
$("#quantity_img2").val(value);
DEMO
Why this happen
Because #quantity_img2
is an input field
, a form
element and to set value to input
field require .val()
method.
So your code should look like
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value); // not .text()
).keyup();
add a comment
|
$("#quantity_img2").text(value);
should be
$("#quantity_img2").val(value);
DEMO
Why this happen
Because #quantity_img2
is an input field
, a form
element and to set value to input
field require .val()
method.
So your code should look like
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value); // not .text()
).keyup();
add a comment
|
$("#quantity_img2").text(value);
should be
$("#quantity_img2").val(value);
DEMO
Why this happen
Because #quantity_img2
is an input field
, a form
element and to set value to input
field require .val()
method.
So your code should look like
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value); // not .text()
).keyup();
$("#quantity_img2").text(value);
should be
$("#quantity_img2").val(value);
DEMO
Why this happen
Because #quantity_img2
is an input field
, a form
element and to set value to input
field require .val()
method.
So your code should look like
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value); // not .text()
).keyup();
answered Jun 4 '12 at 16:31
thecodeparadoxthecodeparadox
75.7k21 gold badges126 silver badges157 bronze badges
75.7k21 gold badges126 silver badges157 bronze badges
add a comment
|
add a comment
|
Use .val()
in place of .text()
like this
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value);
).keyup();
Working fiddle
add a comment
|
Use .val()
in place of .text()
like this
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value);
).keyup();
Working fiddle
add a comment
|
Use .val()
in place of .text()
like this
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value);
).keyup();
Working fiddle
Use .val()
in place of .text()
like this
$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").val(value);
).keyup();
Working fiddle
answered Jun 4 '12 at 16:33
Prasenjit Kumar NagPrasenjit Kumar Nag
12.8k2 gold badges39 silver badges55 bronze badges
12.8k2 gold badges39 silver badges55 bronze badges
add a comment
|
add a comment
|
I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:
$.fn.val2 = function (newVal)
// Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
// http://learn.jquery.com/plugins/basic-plugin-creation/
// use, get mode: var val = $("#" + id).val2();
// use, set mode: $("#" + id).val2("fred");
if (this !== undefined)
// newVal indicates set vs get mode
if (newVal === undefined)
var ret = "";
if (this.attr("value") === undefined && this.prop("value") === undefined)
ret = this.text(); // this is a span
else
ret = this.val(); // this would be an input
return ret;
else
if (this.attr("value") === undefined && this.prop("value") === undefined)
this.text(newVal); // this is a span
else
this.val(newVal); // this would be an input
;
Usage Examples:
Get mode:
var txt = $("#MySpan").val2();
var txt = $("#MyInput").val2();
Set mode:
$("#MySpan").val2("fred");
$("#MyInput").val2("fred");
add a comment
|
I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:
$.fn.val2 = function (newVal)
// Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
// http://learn.jquery.com/plugins/basic-plugin-creation/
// use, get mode: var val = $("#" + id).val2();
// use, set mode: $("#" + id).val2("fred");
if (this !== undefined)
// newVal indicates set vs get mode
if (newVal === undefined)
var ret = "";
if (this.attr("value") === undefined && this.prop("value") === undefined)
ret = this.text(); // this is a span
else
ret = this.val(); // this would be an input
return ret;
else
if (this.attr("value") === undefined && this.prop("value") === undefined)
this.text(newVal); // this is a span
else
this.val(newVal); // this would be an input
;
Usage Examples:
Get mode:
var txt = $("#MySpan").val2();
var txt = $("#MyInput").val2();
Set mode:
$("#MySpan").val2("fred");
$("#MyInput").val2("fred");
add a comment
|
I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:
$.fn.val2 = function (newVal)
// Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
// http://learn.jquery.com/plugins/basic-plugin-creation/
// use, get mode: var val = $("#" + id).val2();
// use, set mode: $("#" + id).val2("fred");
if (this !== undefined)
// newVal indicates set vs get mode
if (newVal === undefined)
var ret = "";
if (this.attr("value") === undefined && this.prop("value") === undefined)
ret = this.text(); // this is a span
else
ret = this.val(); // this would be an input
return ret;
else
if (this.attr("value") === undefined && this.prop("value") === undefined)
this.text(newVal); // this is a span
else
this.val(newVal); // this would be an input
;
Usage Examples:
Get mode:
var txt = $("#MySpan").val2();
var txt = $("#MyInput").val2();
Set mode:
$("#MySpan").val2("fred");
$("#MyInput").val2("fred");
I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:
$.fn.val2 = function (newVal)
// Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
// http://learn.jquery.com/plugins/basic-plugin-creation/
// use, get mode: var val = $("#" + id).val2();
// use, set mode: $("#" + id).val2("fred");
if (this !== undefined)
// newVal indicates set vs get mode
if (newVal === undefined)
var ret = "";
if (this.attr("value") === undefined && this.prop("value") === undefined)
ret = this.text(); // this is a span
else
ret = this.val(); // this would be an input
return ret;
else
if (this.attr("value") === undefined && this.prop("value") === undefined)
this.text(newVal); // this is a span
else
this.val(newVal); // this would be an input
;
Usage Examples:
Get mode:
var txt = $("#MySpan").val2();
var txt = $("#MyInput").val2();
Set mode:
$("#MySpan").val2("fred");
$("#MyInput").val2("fred");
answered Mar 28 at 22:04
Jeff MerglerJeff Mergler
6948 silver badges19 bronze badges
6948 silver badges19 bronze badges
add a comment
|
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%2f10884730%2fjquery-copy-form-inputs-with-keyup%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