I'm trying to get value from 1st input and show same value in a 2nd input
But value is not showed in 2nd taxt box.
Where I'm wrong?
Thanks a lot.
<div class="rowElem"><label>COGS:<span class="req">*</span></label><div class="formRight"><input type="text" name="cogs" id="cogs" value="<?=$_POST[cogs]?>" onchange="run(cogs)/></div><div class="fix"></div></div>
<script>
function cogs(sel) {
var name=document.form1.cogs.value;
}
</script>
<div class="rowElem"><label>COGS:<span class="req">*</span></label><div class="formRight"><input type="text" name="cogs" id="cogs" value="cogs"/></div><div class="fix"></div></div>
Here you have an example about how to assing the value of a input to another
<input type="text" name="cogs1" id="cogs1" value="<?=$_POST[cogs]?>"
onchange="cogs(this.value)"/>
<input type="text" name="cogs2" id="cogs2" value="cogs"/>
<script>
function cogs(value) {
document.getElementById("cogs2").value = value;
}
</script>
Related
In my javascript code i have 4 input fields and one submit button. When click on SUBMIT button the first input field value should be fix not to change and remaining 3 input fields should reset to empty fields after filling some data.
And I am calling page refresh function in SUBMIT button.
So whenever i am clicking to submit button my first input also getting refresh.
Could any one please look into that and help fix this issue.
Thanks in advance....
<!DOCTYPE html>
<html>
<head>
<script>
function refreshPage(){
window.location.reload();
}
</script>
<script>
function incrementValue(){
var value = " " + parseInt(document.getElementById('number').value);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = "00" + value;
}
</script>
</head>
<body>
<form>
First Input Value should set after refresh page : <input type="text"
id="number" value="001" readonly/><br>
Second Input Value should reset : <input type="text" autofocus /><br>
Third Input Value should reset: <input type="text" autofocus /><br>
Forth Input Value should reset : <input type="text" autofocus /><br>
<button type="submit" onclick="incrementValue(), refreshPage()"
>Submit</button>
</form>
</body>
</html>
Try using localStorage, which allows you to get information from webpage even after refreshing it.
https://www.w3schools.com/jsref/prop_win_localstorage.asp
Get the input text field value on tool-tip.for me I am using text-box with autocomplete..when ever i selected in autocomplete it will show in text-box. when i hover it i want tool-tip the value in text-box..how to get that one can anyone can help me
<input type="text" value="something" class="curate">
Use the title attribute and pass the value of the input into the it on the keyup event.
$(document).ready(function(){
$('#testInput').keyup(function(){
$(this).attr('title',$(this).val())
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Type Something
<input type="text" title="" value="" id="testInput">
The first, you set the title is the value,
and do the same when you change the value of textbox
function updateTitle(me)
{
me.title=me.value;
}
<input type="text" title="something" value="something" id="one" class="curate" onchange="updateTitle(this)">
I'd suggest:
$('input.curate').on('change', function (){
this.title = this.value;
});
<input type="text" id="one" value="something" class="curate">
<script>
var x=document.getElementById("one");
x.title=x.value;
</script>
You can using on hover to all inputs in you html like that :
$('input[type="text"],input[type="number"],input[type="date"]').hover(function() {
$(this).attr('title', $(this).val()); });
Here is my HTML:
<form name='cred' class="panel-body2">
<div class="form-group">
<label for='addjidlbl'> Username (JID):</label>
<input type='text' id='addjid' />
</div>
<input type='button' id='add' value='add' />
</form>
Here is the JavaScript:
$('#add').bind('click', function() {
var jid = $('#addjid').value;
alert(jid);
//var jid=document.getElementById('addjid').value;
var jid2 =$('#addjid').get(0).value;
alert(jid2);
// //$('#addjid').get(0).value;
log('jid=>'+jid);
var data = document.getElementById("addjid").value; //$(".panel.panel-default2#addjid").value;
alert(data);
alert("type=>"+ typeof(jid));
addRoster(jid);
});
function addRoster(jid) {
log('addRoster=>' + jid);
}
What I get are two message boxes with "undefined" and third with "type=>undefined". Why can't I get the input text of the addjid text box?
If I change var jid = $('#addjid').get(0).value;, jid is just blank even when the textbox has value. Why?
Change .value to .val() like
$('#addjid').value
should be
$('#addjid').val()
Here you have it working using .val()
add some text to the text box and
click on the add button and the alert will popup
$('#add').on('click', function() {
alert($('#addjid').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name='cred' class="panel-body2">
<div class="form-group">
<label for='addjidlbl'> Username (JID):</label>
<input type='text' id='addjid' />
</div>
<input type='button' id='add' value='add' />
</form>
If I understand correctly, you want:
$('#addjid').val()
Since you are using id's to get the value you will only have one element with the given id. When you do .get(0) or any index you are typically trying to get the value out of a given array of values. For Ex
<li>first</li> //0
<li>second</li> //1
Here in a structure like this you will do something like
$("li").get(0)
It will give you the first item with in li.
and to get the value you will need to use .val()
So you can use
$('#addjid').val()
Hope this helps you.
Happy Learning :)
i want to display one text box value in another text box while clicking button. im able to show value on div but not in text box
Here is the JS
$(document).ready(function(){
$("#btnSubmit").click(function(){
var val= $("#txtValue").val();
$("#txtValue1").text(val);
$("#myDiv").text(val);
})
});
Here is the HTML
<input type="text" id="txtValue">
<div id="myDiv"></div>
<input type = "button" id = "btnSubmit" value="Submit">
<input type="text" id="txtValue1" text="">
For an input type='text' you need:
$("#txtValue1").val(val);
It is an input; inputs take values
Demo
I want to get value of one textbox and put the same in another textbox.
my code is :
<input type="text" value="Keyword" id="one" />
<input type="text" value="Search" id="two" />
button
jquery:
var input = $("#one");
$('#btn').click(function(){
alert('dgdhjdgj');
var oneValue = $('#one').val();
alert("one value "+ oneValue);
var twoVal = $('#two').val($(input).attr('value'));
alert('two Val' + twoVal);
});
demo is here.
Issue : when I change the value of textbox #one, it does not change the value of #two.
thanks in advance.
$(input).attr('value') gets the value of the value attribute, which is the initial value, not the current value.
You had it right two lines earlier. Use val().
Try this
HTML
<input type="text" placeholder="Keyword" id="one" />
<input type="text" placeholder="Search" id="two" />
button
Script
$('#btn').click(function() {
var oneValue = $('#one').val();
$('#two').val(oneValue)
})
Fiddle
write textarea and check it. JSFIDDLE
$("#add").click(function(){
var thenVal = $("#textarea_first").val();
$("#textarea_second").val(thenVal);
});
if all that you want to change the text of second textbox, as soon as you change the text of first textbox, just use jQuery's change event.
just try this then:
$('#one').on("change",function(){
$('#two').val($(this).val());
});