How do I pass a JS boolean to hidden CFINPUT field when a user has edited text in a specific input text field?
Let say this is your field
<input type="text" id="textbox1" value="abc def" name="somename1" onchange="passToHiddenField()" />
And this is your hidden input field
<input type="hidden" id="hidden1" name="somename2" value="" />
Then add the script function
<script>
function passToHiddenField(){
document.getElementById('hidden1').value = 1; //do whatever you want in this function.
}
</script>
Related
I'd like to assign an input value to a hidden fold on submitting a form
<input name="fdata_ini" type="text" id="fdata_ini" value="123" />
this is the hidden field
<input type="hidden" name="fdata_ini_it" id="fdata_ini_it" value="" />
and the jQuery function
jQuery("form1").submit(function(){
var ini_it;
ini_it = jQuery("#fdata_ini").val();
jQuery("#fdata_ini_it").val(ini_it);
})
but for me it does not work.
I have 3 input elements. i want to use onkeyup event to get the value from the first input and copy it to the third input. But I still get an empty value in the third input when i typed in the first one. The function changethree() does not automatically get value from input second when user typed in input first. Please help me
<html>
<input type="text" id="satu" onkeyup="changetwo(this)" placeholder="input 1">
<br><br>
<input type="text" id="dua" onkeyup="changethree(this)" placeholder="input 2"><br><br>
<input type="text" id="tiga" placeholder="input 3">
<script>
function changetwo(a){
var target = document.getElementById('dua');
target.value = a.value;
}
function changethree(a){
var target = document.getElementById('tiga');
target.value = a.value;
}
</script>
</html>
changethree() only fires when the user types something into dua. If you want tiga to be updated when you type in satu you have to add to its keyup event:
<input type="text" id="satu" onkeyup="changetwo(this); changethree(this)" placeholder="input 1">
I am providing multiple check-box and radio button when i enter any value in text field than the same value will assign to radio button and How it is possible using jQuery. Below is the image for reference. I am storing Question and multiple answer and i am going to store true answer out of them like shown in image.
$data = array();
for($i=0,$j=1;$i<count($_REQUEST['quiz_options']);$i++,$j++)
{
$data["quiz_Options".$j] = $_REQUEST['quiz_options'][$i];
}
$data["quiz_Id"] = $Quiz_ID;
$data["quiz_Correct_Answer"] = $_REQUEST['quiz_opt'];
$quiz->insertOptions($data,'quizoptions');
<input class="col-md-4" type="text" name="quiz_options[]" value=""/>
<input type="radio" name="quiz_opt[]" value=""/>
//Here I want to assign my textfield value to the radio button when i write something in my text field.
Please see the example here
You could attach a keydown event to the the textbox and update the value of the radiobutton.
something like this(pseudocode):
$('#textboxId').on('keydown',function(){
$('#radiobuttonId').val($(this).value);
});
Maybe you can use a data attributes (HTML5)
Example
:)
You have to on blur or onchange and should use one class for all dynamic textbox creation. try this code
<input name="quiz_options[]" class ="changesNo1" value="" />
<input name="quiz_options[]" class ="changesNo1" value="" />
<input name="quiz_options[]" class ="changesNo1" value="" />
<input type=radio value="" name="quiz_opt[]">
<input type=radio value="" name="quiz_opt[]">
<input type=radio value="" name="quiz_opt[]">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var test_arr = $("input[name='quiz_options[]']");
$(document).on('change keyup blur','.changesNo1',function(){
$.each(test_arr, function(i, item) {
$("input[name='quiz_opt[]']").val($(item).val());
var d=$("input[name='quiz_opt[]']").val(); // your reference
//alert(d); // This alert for your reference
});
});
</script>
Okay, I have javascript to calculate a dynamic price for an HTML form. The code is as follows:
jQuery("input[name='Amount']").change(function() {
if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) {
jQuery(this).val('');
return false;
}
var calc = parseFloat(this.value) * 0.95;
jQuery(this).parents("form").find("input[name='price']").val(calc);
});
This, with this input:
<input class="irrelevant typeahead" type="text" placeholder="Amount" name="Amount"/>
The javascript takes that value, calculates the price, and I want it to fill this:
<input type="hidden" name="price" value=""/>
I believe my javascript is correct. What do I need to do to the price to make it work?
Make sure you have these items wrapped in a <form> tag.
<form>
<input class="irrelevant typeahead" type="text" placeholder="Amount" name="Amount"/>
<br />
<input type="hidden" name="price" value=""/>
</form>
jQuery("input[name='Amount']").change(function() {
if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) {
jQuery(this).val('');
return false;
}
var calc = parseFloat(this.value) * 0.95;
jQuery(this).parents("form").find("input[name='price']").val(calc);
});
I have a working demo here: http://jsfiddle.net/P55ge/
In the demo I have made the price input a text field instead of a hidden field for ease of seeing the value being set.
Also note, that the field is only updated when you enter a valid number and then click off the field input. The following quote is from the jquery documentation for .change() http://api.jquery.com/change/
Now when the second option is selected from the dropdown, the alert is
displayed. It is also displayed if you change the text in the field
and then click away. If the field loses focus without the contents
having changed, though, the event is not triggered.
I have the following code for a HTML form:
<input type="text" name="myText" value="Enter Your Name" readonly>
<input type="button" onclick="inn()" value="edit">
When I click on the edit button I would like the read only property of the textfield to be removed so that the user can edit the value of the text-field. I do not want to change any other property.
I also do not want to edit the entire form also with:
formId.innerHTML=
The above code shows only one text-field and one button. On my page there are 12 text-fields and 5 buttons. I would like to remove the property not re-edit the entire property again.
Please suggest some JavaScript code that would help.
function inn()
{
// What do I type here to remove the readonly property of the "MyText" text-field?
}
Firstly, you need to get the <input> element from DOM. One possible way:
var element = document.getElementsByName("myText")[0];
Then, to remove readonly you can either change the readOnly property:
element.readOnly = false;
or to explicitly remove the attribute:
element.removeAttribute("readonly");
Try:
Give an ID to your input element:
HTML
<input type="text" name="myText" id="myText" value="Enter your name" readonly />
JS
function inn() {
document.getElementById('myText').readonly = false;
}
First Assign an ID to your textbox.
i.e.
<input type="text" name="myText" id ="txt" value="Enter Your Name" readonly>
<input type="button" onclick="inn()" value="edit">
Then you can write in your javascript -
function inn()
{
if ($('#txt').attr("readonly") == true)
{
$('#txt').val('');
$('#txt').removeAttr("readonly");
}
}