HTML or JavaScript to multiply [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Here is what I have been trying to figure out for days now. I have some code already typed up that outputs a number based on what check boxes are checked. What I want now is some code that grabs the number from that numberbox and multiplies it by a set number in a different numberbox.
Here is the JavaScript that I swiped from somewhere to try and get this to work but to no avail.
<script type="javascript">
function calculate() {
var myBox1 = document.getElementById('ttl').value;
var myBox2 = document.getElementById('ttl2').value;
var result = document.getElementById('result');
var myResult = myBox1 * myBox2;
result.innerHTML = myResult;
}
</script>
And here is the HTML that I am trying so hard to bash against it to make it work.
<input type="number" id="ttl" value=729><br>
<input id="result" />
The check boxes add more to the base of 729 and I want the lower box to multiply by 1.1
Any help out there for a code moron?
EDIT:
I don't know of much other way to ask this. I have a value that is put into a numberbox. I want a second numberbox that grabs the first box's number on the fly and multiply it by a set number which happens to be 1.1. Like I commented before, I know what I want to ask, but I don't know how to ask it exactly

The element with the id result is an input box:
<input id="result" />
Change result.innerHTML = myResult; to result.value = myResult; and the calculated number will be displayed there. See on JSFiddle.

Related

HTML5 Canvas how to automatically keep track of text user input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
This is the code if you want to try it out:
https://jsfiddle.net/csCoder/eLxfrn10/8/
I currently have 2 textboxes from the user will type in their input and when they press "draw line", then the input is read and a line is drawn accordingly. I want to make it so that the line will automatically be drawn whenever the user inputs anything in the textbox (without having to click on a button) OR whenever the user uses the slider.
Currently the lines that I drew changed based on what is typed into the textbox. However, I have a slider that updates the text box and I want my program to keep track of the slider AND the textboxes instead of just the textboxes if that makes sense. I appreciate your help!
This is what it looks like right now:
Picture
I cleaned up the code to make it easier and more relevant:
This code snippet represents the slider and the textbox (user should be able to use either to input numbers).
<input id="rangeInputM" type="range" min="-10" max="10" oninput="m1.value=rangeInputM.value" />
<input id="m1" type="number" value="1" min="-200" max="200" oninput="rangeInputM.value=m1.value" />
This is where I am having trouble getting my drawing to update whenever I either input new text or move the slider. Using #m1 as the selector works for updating the text box, but I am trying to get both the textbox (#m1) and the slider (#rangeInputM) to work:
$("#rangeInputM").keyup(function(){
var m1,b1 = 0;
m1 = parseFloat($("#m1").val());
b1 = parseFloat($("#b1").val());
var myGraph = new Graph({
canvasId: 'Graph',
minX: -10,
minY: -10,
maxX: 10,
maxY: 10,
unitsPerTick: 1
});
myGraph.drawLine(m1, b1, 'blue', 3);
});
Thanks!

How to restrict input box to only accept postive numbers and have a maxium value of 10 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Im trying to only use javascript to accept positive numbers in the input field
I've tried to use this, but don't know how to set a max value of 10.
if (Number.isInteger(num) && num >= 0) {
}
Try this:
if (Number.isInteger(num) && num >= 0 && num <= 10) {
}
You can also do the min/max attribute thing mentioned in the comments, although do be warned that that has different implementations per browser and isn't supported on IE 9 and below.
the best solution is to set it initially and then adjust the range on them.
This will allow you to dynamically change them from javascript as needed. This function should suit your needs and is reusable.
<input id = "myControlID" type="number" max="10" min="1" >
<script>
setNumberRange(0, 100, "myControlID"); //usage
function setNumberRange(minValue, maxValue, selector) {
var input = document.getElementById(selector);
input.setAttribute("min", minValue);
input.setAttribute("max", maxValue);
}
</script>
You can just try this on the input tag
<input type="number" max="10" min="1" >
Hope it helped

javascript code of picking td value from the screenshot below [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
From the screenshot below, two questions as newbie of javascript developer.
I want to directly get the value of the second td from $('#cart-subtotal-order.total.subtotal td') in javascript code. That is the first question. The second question is how to get the value of $('.amount grand-total'). Is it right to use val() for that like this $('.amount grand-total').val() or should I use text() for the regular text value for that?
HTML Body elements source screenshot
if you wat to get second td from tr:
var subtotal = $('#cart-subtotal-order.total.subtotal').find("td:eq(1)").text();
then if you want to get grand total is like:
var grand_total = $('#totalRow .grand-total').text();
For Getting Second row text, you can use the following code
var seondRow = $("table>#cart-subtotal-order.total.subtotal> td:nth-child(2)").text();
For Getting the grand total
var grandTotal = $('#totalRow .grand-total').text();
or
var grandTotal = $('#totalRow .grand-total').value();

Unable to get data from dynamically created textfield in javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a small project where i created text fields based on user input.
$('#arraySizeButton').click(function() {
var arraySize = $("#arraySize").val();
if(arraySize=='') {
alert("Enter Some Text In Input Field");
}else{
var count = arraySize;
var html = [];
while(count--) {
html.push("\<input type='text' id='inputTextField", count, "'>");
}
$('#inputTextFieldsarea').append(html.join(''));
}
});
I want to create a dynamic program based on above code and retrieve data from textfields to an array. Appreciate your help.
Did you mean this?
html.push("<input type='text' id='inputTextField"+count+"'/>");
What you should do is add a [] to the name of the input, to let the html form know that this is an array.
You should do something like that:
html.push("\<input name='field[]' type='text' id='inputTextField", count, "'>");
And using php to get the content of all the POSTed fields you could simply check
$_POST['field']
which is an array.
EDIT: IF you want to do this using jquery as you stated in your comment, then you could do it like that:
$('[id^="inputTextField"]').each(function() {
alert($(this).val());
});

How to add new text field when button is clicked [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create a form for my client. My client require to create a dynamic for him.
Suppose, I want to insert 1 record in main table of mysql, and record multiple records in secondary table which has reference key of main table. I don't know how many records against the main table, it maybe one at time or multiple records at time. I want to do it with single form. If client click add more button it show another text field to insert more data.
how I can do it ?????
It would be possible using pure javascript
like this
<input type="button" onclick="addInput()"/>
<span id="responce"></span>
<script>
var countBox =1;
var boxName = 0;
function addInput()
{
var boxName="textBox"+countBox;
document.getElementById('responce').innerHTML+='<br/><input type="text" id="'+boxName+'" value="'+boxName+'" " /><br/>';
countBox += 1;
}
</script>
This is possible through the jquery/javascript.
So you can use this reference :http://www.mkyong.com/jquery/how-to-add-remove-textbox-dynamically-with-jquery/
Just try it!!
here is the code:
function generateTextBox()
{
var mainDiv=document.getElementById('options');
alert(mainDiv);
var newBreak=document.createElement('br');
mainDiv.appendChild(newBreak);
for(var i=1;i<=4;i++)
{
var newTextBox=document.createElement('input');
var newBreak1=document.createElement('br');
var newBreak2=document.createElement('br');
var newBreak3=document.createElement('br');
var text = document.createTextNode("Option"+i);
newTextBox.type='text';
newTextBox.setAttribute('id','txtAddr'+i);
alert(newTextBox+"2");
mainDiv.appendChild(text);
mainDiv.appendChild(newTextBox);
mainDiv.appendChild(newBreak1);
mainDiv.appendChild(newBreak2);
mainDiv.appendChild(newBreak3);
}
}
This isn't php related, you'll need to dynamically add to the form using javascript.

Categories

Resources