Javascript Function To Output Information With An Input During Process - javascript

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.

Related

How to count all blank cells in a column with Google Sheet Script Code and showing results in message box

Can someone please help?
I have a Google Sheet and as soon as I open the file I need to show a pop-up message displaying the total of blank cells in column M. I do not need to write the value in the sheet. I simply need the script code to do the calculation and show the quantity of empty cells in the message box. Also, I need the code to start counting from M3 and as far as the last row containing data in column M (it needs to find that last row automatically).
I've tried the following, but obviously is not working, it's far from working:
function alertMessage() {
var Formula = "=COUNTBLANK(M3:M)";
var result = SpreadsheetApp.getUi().alert("Empty cells total:" &Formula);
if(result === SpreadsheetApp.getUi().Button.OK) {
}
}
Thank you so much.

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

Running javascript on page back

I have the following problem:
I've created a form with several input fields like these:
<td>Pizza Margherita</td>
<td><input type="number" id="countMargherita" class="formnumbers" name="PizzaMargherita" onChange="validateForm(this);changeTotalFromCount(this);" data-unitprice="7"/></td>
<td><span id="totalMargherita"></span></td>
11 to be exact.
the onChange="changeTotalFromCount(this)" looks as follows:
function changeTotalFromCount(input) {
var unitPrice = parseFloat(input.getAttribute("data-unitPrice"));
var count = input.value;
var price = unitPrice * count;
var formattedPrice = '\u20ac ' + price.toFixed(2);
var label = input.parentNode.nextElementSibling;
label.innerHTML = '';
label.appendChild(document.createTextNode(formattedPrice));
}
Now what this does is say the user wants 5 pizza margherita's he enters a 5 in the input field and then immdediately shows the cost which in this case is 7*5= 35. This works just fine, but when the user submits the form he gets taken to another .php file where he sees the confirmation with all the details. There is also a button that needs to take them back to the order page again. I did this first by just sending it straight to my orderform.php but as this doesn't save the customer his input i decided to use this instead:
<input type='button' value='Bestelling Wijzigen' onClick="history.go(-1);return false;" class='printbutton'>
I don't know if this is the right thing to do or not, but i saves the user's his information as he goes back. Except it doesn't show the prices next to the input anymore unless he/she changes the input again. And there lies my problem, i'd like it so that if the user goes back to change his order he can still see the costs of each product without changing it before he can see it again.
Im not really an expert in JS or PHP.
(if you miss any information please let me know!)
You can use the onload event to run code that initializes all totals. It's fired when you go to a page with the backbutton as well as when you visit it in any other way.
So, for example
function initTotals()
{
var inputs = document.getElementsByTagName('input');
for(var i=0; i < inputs.length; i++)
{
changeTotalFromCount(inputs[i]);
}
}
window.onload = initTotals;
http://jsfiddle.net/XK99Z/

Print multiplication table of any number in an alert box in 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

How to call getJson multiple times and pass it values after it finishes the first passed item?

I have a getjson call that I want to pass some items to it. I wonder how I can call this getjson multiple times and pass them values such as book, pen, paper,... and if those items are on sale display them in different iframes as shown below (for example I want to check 10 items if they are on sale)?
At the moment, my code only processes one item, but I want it to process 10 items and display those items that are on sale.
Furthermore, I want to do this sale checking process for a list of items every 10 min if the user is in the page, without the user having to reload the page. Could you guys show me how this can be done?
<script src="http://anyorigin.com/jquery-1.4.2.min.js"></script>
<script>
$.getJSON('http://anyorigin.com/get?url=http://www.awebsite.com/item=book/&callback=?', function(data){
var siteContents = data.contents;
//writes to textarea
//document.myform.outputtext.value = siteContents;
var n=siteContents.search("This item is not on sale");
alert("value of n:"+n);
if(n=-1) {
alert("item book is on sale. n:"+n);
$('#ItemBookWrapper').show();
//if the passed item is on sale display that item in a iframe if its not on sale go //to next item. so at
} else {
alert("item:book is not on sale");
}
});
</script>
</head>
<body>
<div id="ItemBookWrapper" style="display:none">
<iframe src='http://www.awebsite.com/item=book' height=200 width=200 style='border: none;'></iframe>
</div>
<br>
I wonder how I can call this getjson multiple times and pass them values such as book, pen, paper
If this is the format that the website uses...
http://www.awebsite.com/item=book/&callback=?
where you'd get the book, the pen the paper... you'd just create a string
var getJSONurl = "http://anyorigin.com/get?url=http://www.awebsite.com/item=" + itemType +/&callback=?"
and then
$.getJSON(getJSONurl, function(data) {
// your code
}
At the moment, my code only processes one item, but I want it to process 10 items and display those items that are on sale
seeing the JSON structure would help greatly with that one, but, normally with json you'd use...
obj = JSON.parse(data);
and then use an iterator and to cycle through all of the data objects that you have.
I want to do this sale checking process for a list of items every 10 min if the user is in the page, without the user having to reload the page
That you'd use a (setInterval)[https://developer.mozilla.org/en-US/docs/DOM/window.setInterval] function...
Where you'd use
var interval = window.setInterval(yourJSONfunction(), 60000)
where 60000 is time in milliseconds (600 seconds = 10 minutes). When the page loads it'll call every 10 minutes. You could set a variable to be whatever you'd like it to be calling, whether it's books, paper, whathave you. And use that to complete the string.

Categories

Resources