Print multiplication table of any number in an alert box in Javascript - javascript

I want to show a table (multiplication one) after taking number (as an input) from user in an alert box. But the problem is under loop, as loop runs 10 times, alert box also is shown 10 times. I've tried using id, wrote alert code outside loop but it doesn't work correctly. So is it possible to show the output in one alert box instead of showing it in 10 alert boxes? Also alert box don't seem to be interpret "br" correctly. Is there any other way of doing it?

The problem is that placing alert in a for loop will... show one alert with one number, followed by another alert with another number, etc.
You want to first create the whole body of the alert (using the for loop) and after that alert once.
<script>
function table()
{
var x=prompt("Enter a number:",2);
var alertBody = '';
for (var i=1; i<10; i++) {
alertBody += x + "*" + i +"="+x*i + '\n';
}
alert(alertBody);
}
</script>
Working example: http://jsbin.com/oVuwINa/1/edit

What about \n instead of br?
if you are doing it this way
Alert -> get input
loop and store your result
Alert -> show output
then it should be working fine

Related

Javascript Function To Output Information With An Input During Process

I am currently writing a roulette system tracker. I currently have the below code that waits for a button press on numbers 0-36 and then produces a line of results including Number, whether Red/Black, whether Odd/Even, Hi or Lo, etc dependent on the button pressed, worked out by a function handle results (), outputted in the #results window. Then the code waits for another number and the process is repeated on the next line. ( In this case, I have the newest line of results showing at the top, and older lines get shifted down.)
<html>
<div id="results" class="resultwindow"></div>
<script>
function spin(number) {
var color = roulette(number);
handleResults();
var resultsDiv = document.getElementById("results");
var resultHTML = `${number}`;
resultHTML = 'div class="... ( display result and properties ) ....</div>';
resultsDiv.innerHTML = resultHTML + resultsDiv.innerHTML;
resultsDiv.scrollTop = 0;
}
</script>
</html>
Now I want to change the behavior of each line to such: Firstly show details of what bets are to be placed calculated by the function handleBets(), then wait for the input of a button press for the Number, then when pressed show the results calculated by handle results on the same line. Then this line of information is finished and the code should recall handleBets() again and start another line showing the bets to be placed, and wait for the input of Number again, and so on.
The implementation of this is a little out of my reach. When I have been trying the 'display bets' and 'display results' are ending up on the same line, not with the latest 'display bets' on a new page waiting for the Number before 'display results' is executed.
Any help would be greatly appreciated.

JavaScript Button input and output reset

I'm working with a button and a text label in javascript and HTML. I have a code that clears the input text label, but i also need the same button to clear the output message it gives = "helloNameOP". How would I add the 2 in the same function? I have both my codes listed below, that work perfectly separated, but I cant figure out how to put them together to work simultaneously.
What I have tried:
//for removing the Input text label:
onclick = document.getElementById("helloNameInput").value="";
//for removing the Output message recieved:
inputField = document.getElementById("helloNameOP")
document.getElementById('helloNameOP').textContent = " "
I'm not a javascript person, more of a kotlin gal, so I'm trying to learn.
If I’m understanding correctly, you can get a reference to the button, and then add an event listener.
document.getElementById("the-button-id").addEventListener("click", function () {
document.getElementById("helloNameInput").value = "";
document.getElementById("helloNameOP").textContent = "";
});

Duplicating a repeating table row in livecycle designer

I have a table on one page in a Livecycle Designer form and would like the repeating row to duplicate to another table on a different page. I have this working on the first table on the first page to the table on the second using the exit event however, if the same information on the second table stays the same, because it is on the exit event, it does not copy to the new table on page 3.
I have this code in table 1 on page 1 on the exit event which works:
xfa.resolveNode("Month2.Performancegoals2.updates.details[" + this.parent.index + "]").projectName.rawValue = this.rawValue;
I thought this code would work using a button which unhides page 2
xfa.resolveNode("Month1.Performancegoals2.updates.details[" + this.parent.index + "]").projectName.rawValue = xfa.resolveNode("Month2.Performancegoals2.updates.details[" + this.parent.index + "]").projectName.rawValue
but this does not work. Actually when a value is placed in the field and the button is clicked, the entered value disappears.
Can anyone help? I'm out of time!
OK, looks like you're assigning values backwards. Values in Javascript are assigned from right to left. So, whatever is on the right of the '=' get put into the left side.
e.g.,
x=5; //assigns the value 5 to x
y=x; //assigns whatever is in x to y
Month1 = Month2; //Month2 is assigned to Month1.
If Month2 is blank, then Month1 becomes blank

Jquery each loop showing first value as zero or NaN

I am using jquery to gather data from a dynamically created table via Jquery. I am able to get the data, but now I want to sum up the fields and put the result inside a text field or label etc dynamically when I press enter. I am using the following code:
$("#iq").keypress(function(e)
{
if(e.which==13)
{
var tot=0;
$('#tab .itemtotal').each(function()
{
tot = tot + parseInt($(this).html());
});
$("#totalamount").val(tot);
}
});
My problem is that the value showing in the textfield is zero or NaN for the first time and after that its calculating correctly. I used the same code and associating it with a button and checking its click event and its working properly and showing first item also.
Any suggestions? If need some more clarification let me know. Thanks in advance.

Javascript while loop failure

Into a php page I have 20 text boxes. I want to make a button, using javascript, and when user clicks on it the rest 19 text boxes to take 1st text box's text. I have done something like this but it isn't working... Any idea?
function Throw_PhotoStuff(){
var pcount=1;
while(pcount<20;){
document.getElementById('photo_'+pcount).value = document.getElementById('photo_1').value; pcount++;
}
}
remove the semicolon from while loop, like:
while(pcount<20;){ //will show SyntaxError: missing ) after condition
to
while(pcount<20){
I think you have extra semicolon here
while(pcount<20;){
remove this

Categories

Resources