I want to solve this question with CSS, form, javascript and I tried to do javascript and included 3 if statements but it not really showing me the output
is it because the if statements should each be closed with brackets? or maybe there is a mistake in the way I write the variables I tried many things, and it's not working please help I'm still a beginner programmer and I can't figure it out
function myFunction(){
var Fname= document.getElementById("fname").value;
var Lname= document.getElementById("lname").value;
var Name = Fname + " " + Lname;
var date= document.getElementById("date").value;
var tr= document.getElementById("t").value;
var tour= document.getElementById("tour").value;
var request= document.getElementById("request").value;
var v = Number(document.getElementById("visitor").value);
var city = document.getElementById("city").value;
var x="";
var y="";
var z="";
var total=x+y+z;
{
if (v<=0){
v=prompt(" minimum visitors are 1 try again");
}
else if (city == "Amman $50") {
x = v * 50;
}
else if (city == "Salt $20") {
x = v * 20;
}
else {
x = v * 10;
}
}
{
if ( tour==Yes )
{
y= 50;
}
else {
y=x;
}
}
{
if (trans==Car)
{
z= 30;
}
else{
z=20;
}
}
document.getElementById("result").innerHTML = "Arrival date" + date + "<br>"
+ Name.toUpperCase() +
"<br>"+" City " + city + v + "visitors"
+"<br>" + " transportation " + tr +
"<br>" + "tour leader :" + tour
"<br>"+ "any medical:" + request +
"<br>" +"Amount=$ " + total ;
return false;
};
body{
margin:20px;
text-align:center;
}
form{
background-color:orange;
}
div.sec {
margin-left:300px;
}
div.transpo {
margin-right:450px;
}
<h3 style="text-align:center"> <span style="color:red;font-size:40px;">V</span>isit <span style="color:red;font-size:40px;">J</span> ordan </h3>
<form>
<div class="transpo">
<input type="text" id="fname" size="30" placeholder="First Name">
<br><br>
<select id="city">
<option value="select your city "> Select your city </option>
<option value="50 ">Amman $50</option>
<option value="20 ">Salt $20</option>
<option value="10 ">Jarash $10</option>
</select>
<br><br>
<label><b>Number of visitors</b></label>
<br>
<input type="number" id="visitor">
<br><br>
<label style="margin-right:10px;"><b> Transportation</b></label>
<br>
<input type="radio" id="car" name="transportation" value="car" id="t">
<label id="car" for="car">car $30</label>
<input type="radio" id="bus" name="transportation" value="bus" id="t">
<label for="bus">bus 20$</label><br>
</div>
<div class="sec">
<input type="text" id="lname" size="30" placeholder="Last Name">
<br><br>
<label><b>Arrival Date:</b></label><br>
<input type="date" id="date">
<br><br>
<label><b> Any medical Request:</b></label>
<br>
<textarea rows="1" cols="20" id="request"></textarea>
<br><br>
<label><b> Tour Leader $50</b></label>
<br>
<input type="radio" id="yes" name="tour" value="yes" id="tour">
<label for="yes">yes</label>
<input type="radio" id="no" name="tour" value="no" id="tour">
<label for="no">no</label><br>
</div>
<button type="button" onclick="myFunction()"> PREVIEW </button>
<button type="submit" onClick=""> Submit </button>
</form>
<p style="background-color:#99ccff;width:420px;font-weight: bold;" id="result"> </p>
<p style="background-color:#99ccff;width:420px;font-weight: bold;" id="result2"> </p>
If you open your console in your browser (pressing F12 as default) you can see that the Javascript is returning an error.
Uncaught SyntaxError: "" string literal contains an unescaped line break
This refers two missing quote marks on row 174 and row 176, both are missing on the end of the file.
However your code still don't work, if you press preview you get another error
<input type="radio" id="car" name="transportation" value="car" id="t">
<input type="radio" id="bus" name="transportation" value="bus" id="t">
on these two lines you specify id twice which is not allowed.
Tips so you can more easily solve these issues on your own:
You should start to use the console to find errors in your code.
Try to reread your code and look for small errors like a missing "
If you are unsure how something works like a html or javascript feature use websites like w3school to look up well expained documentation.
Good luck in your future coding adventures.
Related
I need to to enter a new value( the standard manufacturing thickness(SMT)) and divid it on /48 then check if the answer < 135 display (pass) if not display (Enter higher value) I tried if else statement but it doesn't work
and also I want to display the (the standard manufacturing thickness(SMT=)) text input side by side with the MAOP(psi)= text input.
<body>
<label for="formulas">Choose a formula:</label>
<select name="formulas" id="formulas">
<option value="free">Pipeline Thickness</option>
</select>
<h2>Enter inputs</h2>
<label for="P">MAOP(psi)=</label>
<input type="number" id="P">
<br>
<label for="D=">Do(in)=</label>
<input type="number" id="D">
<br>
<label for="SMYS">SMYS(psi)=</label>
<input type="number" id="SMYS">
<br>
<label for="DF">DF=</label>
<input type="number" id="DF">
<br>
<label for="T">T=</label>
<input type="number" id="T">
<br>
<label for="E">E ā
=</label>
<input type="number" id="E">
<br>
<button type="submit" id="calculate">calculate</button>
<br>
<label for="total">Wall Thickness(in)=</label>
<input type="number" id="total" readonly>
<br>
<label for="SMT">Standerd Manufacturing Thickness (in)=</label>
<input type="number" id="SMT">
<br>
<button type="submit" id="check">Check</button>
<script>
document.getElementById('calculate').addEventListener('click', function() {
var P = +document.getElementById("P").value;
var D = +document.getElementById("D").value;
var SMYS = +document.getElementById("SMYS").value;
var DF = +document.getElementById("DF").value;
var T = +document.getElementById("T").value;
var E = +document.getElementById("E").value;
var SMT = +document.getElementById("SMT").value;
var total = (P * D) / (2 * SMYS * DF * T * E);
document.getElementById("total").value = total;
var Check= (SMT / 48);
function myFunction() {
document.getElementById("Check").value = Check;
}
if (SMT / 48 < 135) {
console.log("pass");
} else {
console.log("enter higher value");
}
});
</script>
</body>
I am trying to detect if an HTML FORM in a web page contains ComboBox or List. . I could detect all the rest and here are my efforts so far. As you can see, the ComboBox is not detected. I understand its not an input control. Is there any other way to do this?
MY SAMPLE CODE:
<html>
<head>
<script language="javascript" type="text/javascript">
function detectTypes() {
var str = document.getElementById("Select1").value;
var inputs = document.querySelectorAll('input');
var inputtype = document.getElementsByTagName ("input");
for(i =0; i < inputs.length; i++)
{
//Output result to console
console.log("The " + i + ". input type = " + inputs[i].type);
//Output result to multiline textbox
var s = inputs[i].type;
document.getElementById('output').value += s.substring(s.length - 10) + '\n';
}
}
</script>
</head>
<body>
<form name="form1" id="form1" method="">
<p>
<label>TextBox </label>
<input type="text" id="Name">
</p>
<p>
<label>Password</label>
<input type="password" id=phone>
</p>
<p>
<label>Dropdown Comobox</label>
<select name="Options" id="Select1">
<option value="Jack,12345">Jack</option>
<option value="John,45678">John</option>
<option value="Tom,98765">Tom</option>
</select>
</p>
<P>
<label>CheckBox</label>
<input type="checkbox" id="check1">
<p>
<label>Radio Button</label>
<input type="radio" id="Option1" name="Option1" value="">
<p>
<label>Color Box</label>
<input type="color" name="ColorCode" id="color-picker">
</form>
Click to List types of controls
<p>
<label>RESULT:</label>
<textarea name="output" id="output" rows="7" cols="30"></textarea>
</p>
</body>
</html>
I would praise your work becse it is very creative
I have solved your problem
<html>
<body>
<form name="form1" id="form1" method="">
<p>
<label>TextBox </label>
<input type="text" id="Name">
</p>
<p>
<label >Password</label>
<input type="password" id="phone">
</p>
<p>
<label>Dropdown Comobox</label>
<select name="Options" id="Select1">
<option value="Jack,12345">Jack</option>
<option value="John,45678">John</option>
<option value="Tom,98765">Tom</option>
</select>
<input type="hidden">
</p>
<P>
<label>CheckBox</label>
<input type="checkbox" id="check1">
<p>
<label>Radio Button</label>
<input type="radio" id="Option1" name="Option1" value="">
<p>
<label>Color Box</label>
<input type="color" name="ColorCode" id="color-picker">
</form>
Click to List types of controls
<p>
<label>RESULT:</label>
<textarea name="output" id="output" rows="7" cols="30"></textarea>
</p>
</body>
</html>
/*
//* user script
function detectTypes() {
//var str = document.getElementById("Select1").value;
var inputs = document.querySelectorAll('input');
var inputtype = document.getElementsByTagName("input");
for(i =0; i < inputs.length; i++)
{
//Output result to console
//console.log("The " + i + ". input type = " + inputs[i].type);
//Output result to multiline textbox
var s = inputs[i].type;
document.getElementById('output').value += s.substring(s.length - 10) + '\n' ;
}
} */
function detectTypes(){
// const inputtype = { "'SELECT'" : 'Dropdown' , 'OPTION' : 'Combo Box'} // I wish, it would work as alert(inputtype.SELECT) will show deopdown
var inputs = document.querySelectorAll("input, select");
var s = "hi";
for(i=0;i<=inputs.length;i++){
var tagnames = inputs[i].tagName;
if(tagnames == "INPUT"){
document.getElementById('output').value += inputs[i].type + '\n';
}else{
document.getElementById('output').value += tagnames.toLowerCase() + '\n';
}
}
}
setTimeout(detectTypes, 1);
I would be glad if you contact. I have to discuss further about this problem. Contact me libertmahin#gmail.com
I heard that NaN errors are when you are trying to pass an object as a number, yet in my HTML, 'productquantity' is set as a number, so why is it giving me this error? These files operate with another HTML file and another JavaScript file to retrieve data and these 2 display the data. 'productquantity is what is my only hurdle and where the NaN error comes up. If you need the other HTML and Javascript file, please let me know. Thanks in advance!
"use strict";
function getBooking() {
var laptopsprice = 0;
if (sessionStorage.fname != undefined) { //if sessionStorage for username is not empty
//confirmation text
//outputs user details in payment page and stores values to be sent to server in hidden input tags
document.getElementById("confirm_name").textContent = sessionStorage.fname + " " + sessionStorage.lname;
document.getElementById("confirm_email").textContent = sessionStorage.email;
document.getElementById("confirm_phone").textContent = sessionStorage.phone;
document.getElementById("confirm_streetname").textContent = sessionStorage.streetname;
document.getElementById("confirm_suburb").textContent = sessionStorage.suburb;
document.getElementById("confirm_state").textContent = sessionStorage.state;
document.getElementById("confirm_postcode").textContent = sessionStorage.postcode;
document.getElementById("confirm_laptops").textContent = sessionStorage.laptops;
document.getElementById("confirm_productquantity").textContent = Number(sessionStorage.productquantity);
document.getElementById("confirm_cost").textContent = laptopsprice;
laptopsprice = totalproductcost(sessionStorage.laptops, Number(sessionStorage.productquantity));
//values for hidden input tags that send data to the server
document.getElementById("a_name").value = sessionStorage.fname + " " + sessionStorage.lname;
document.getElementById("a_email").value = sessionStorage.email;
document.getElementById("a_phone").value = sessionStorage.phone;
document.getElementById("a_streetname").value = sessionStorage.streetname;
document.getElementById("a_suburb").value = sessionStorage.suburb;
document.getElementById("a_state").value = sessionStorage.state;
document.getElementById("a_postcode").value = sessionStorage.postcode;
document.getElementById("a_laptops").textContent = sessionStorage.laptops;
document.getElementById("a_productquantity").textContent = Number(sessionStorage.productquantity);
document.getElementById("a_cost").value = laptopsprice;
}
}
function totalproductcost(laptops , productquantity) {
var laptopsprice;
if (laptops == "Workstation_Laptop") {
laptopsprice = (productquantity * 2499);
} else if (laptops == "Gaming_Laptop") {
laptopsprice = (productquantity * 1789);
} else if (laptops == "Laptop_Stand") {
laptopsprice = (productquantity * 64);
} else if (laptops == "Office_Laptop") {
laptopsprice = (productquantity * 1499);
}
return laptopsprice;
}
function cancelBooking(){
window.location = "enquiries.html";
sessionStorage.clear();
}
//function for invoking getbooking and validate, cancel booking
function init() {
document.getElementById("paymentform").onsubmit = validate;
document.getElementById("cancelpurchase").addEventListener("click", cancelBooking);
getBooking();//invokes getbooking function
}
//invokes init fuction on window load
window.onload = init;
<!DOCTYPE html>
<html lang="en">
<head>
<script src="scripts/payment.js"></script>
<title>SwinTech</title>
<link rel="stylesheet" type="text/css" href="css/style.css"> </head>
<header class="enquiriespage">
<div class="main">
<div class="logo"> <img src="logo.png" alt="logo"> </div>
<ul>
<li>Home</li>
<li>Products</li>
<li>Enquiries</li>
<li class="active">>Payment</li>
<li>About</li>
</ul>
</div>
</header>
<section class="paymentthing">
<div class="paymentcontainer">
<fieldset>
<legend>Order Summary:</legend>
<p>Your Name: <span id="confirm_name"></span></p>
<p>Your Email: <span id="confirm_email"></span></p>
<p>Your Phone Number: <span id="confirm_phone"></span></p>
<p>Street name: <span id="confirm_streetname"></span></p>
<p>Suburb: <span id="confirm_suburb"></span></p>
<p>State: <span id="confirm_state"></span></p>
<p>Postcode: <span id="confirm_postcode"></span></p>
<p>Product: <span id="confirm_laptops"></span></p>
<p>Product Quantity: <span id="confirm_productquantity"></span></p>
<p>Total Cost: $<span id="confirm_cost"></span></p>
<input type="hidden" name="name" id="a_name" />
<input type="hidden" name="email" id="a_email" />
<input type="hidden" name="phone" id="a_phone" />
<input type="hidden" name="streetname" id="a_streetname" />
<input type="hidden" name="suburb" id="a_suburb" />
<input type="hidden" name="state" id="a_state" />
<input type="hidden" name="cost" id="a_cost" />
<input type="hidden" name="laptops" id="a_laptops" />
<input type="hidden" name="postcode" id="a_postcode" />
<input type="hidden" name="productquantity" id="a_productquantity" />
</fieldset>
<br>
<br>
<form id="paymentform" method="post" action="https://mercury.swin.edu.au/it000000/formtest.php">
<label for="cardType">Please Choose a Card Type:</label>
<br>
<br>
<select name="cardType" id="cardType" required="required">
<option value="">Please Select</option>
<option value="Visa">Visa</option>
<option value="Mastercard">Mastercard</option>
<option value="American Express">AmEx</option>
</select>
<br>
<br>
<label for="cardName" id="cardName">Please Enter Name On Card:</label>
<input type="text" name="cardName" maxlength="40" required="required">
<br>
<br>
<label>Please Enter Credit Card Expiration Date:</label> <span class="expiration">
<input type="tel" name="month" placeholder="MM" maxlength="2" size="2" required="required" />
<span>/</span>
<input type="tel" name="year" placeholder="YY" maxlength="2" size="2" required="required" /> </span>
<br>
<br>
<br>
<label for="cardNo">Credit Card Number:</label>
<input id="cardNo" type="tel" inputmode="numeric" pattern="[0-9\s]{13,19}" autocomplete="cc-number" maxlength="16" placeholder="xxxx xxxx xxxx xxxx" required="required">
<br>
<br>
<input type="submit" value="Check Out">
<br>
<br>
<button type="button" id="cancelpurchase">Cancel Purchase</button>
</form>
</div>
</section>
<div class="footer">
<div class="footer-content"></div>
<div class="footer-bottom"></div> Ā© swintech.com | Designed by Bilal El-leissy </div>
</html>
Anytime you retrieve or set a value to go in a html tag or form element it is a string. Even if you cast that item as a Number(), the DOM will store it as a string. Whenever that string is to be used in a calculation, convert it to a number then with the plus operator, parseInt or parseFloat, as in:
function totalproductcost(laptops , productquantity) {
productquantity = +productquantity;
// OR productquantity = parseInt(productquantity);
// OR productquantity = parseFloat(productquantity); if you have a decimal to consider
var laptopsprice;
if (laptops == "Workstation_Laptop") {
laptopsprice = (productquantity * 2499);
} else if (laptops == "Gaming_Laptop") {
laptopsprice = (productquantity * 1789);
} else if (laptops == "Laptop_Stand") {
laptopsprice = (productquantity * 64);
} else if (laptops == "Office_Laptop") {
laptopsprice = (productquantity * 1499);
}
return laptopsprice;
}
There are two things you might want to check for.
One is that productquantity has a value. If it's undefined or null, Number will return NaN.
The other is that if productquantity is being set as a string, that the string doesn't contain non-numerical characters.
Adding ".value" to the input helped me
This is my first post and I have searched for days and can not find a solution for this problem.
I have a custom menu in sheets that pops up a .showModalDialog html. A user fills that out with information and clicks submit. This runs a function in the back end that creates folders/files and adds the user data to various sheets etc.
All this is working I have a Ui.alert that I am using to check the data entered is correct and for some reason the function is being trigger twice and the UI.alert is popping up again as a result. I have a fail safe that checks if one of the fields exists so it doesn't write again but the pop up is a really bad user experience.
Any help would be much appreciated.
Function to create custom menu:
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('TOA - Menu')
.addItem('Add New Account', 'addAccount')
.addItem('Update Brand', 'updateBrand')
.addItem('Go Live', 'goLive')
.addToUi();
}
Function to bring up form:
function addAccount() {
const html = HtmlService.createHtmlOutputFromFile('newAccount')
.setTitle('Add New Account')
.setWidth(1000)
.setHeight(800);;
SpreadsheetApp.getUi()
.showModalDialog(html, 'Add New Account');
}
Code for the form:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
#itemDisplay {
display: none;
}
#modDisplay {
display: none;
}
#priceDisplay {
display: none;
}
#businessTypeDisplay {
display: none;
}
</style>
</head>
<body>
<h1>
Add New Account
</h1>
<form id="myForm" onsubmit="handleNewAccountFormSubmit(this);">
<div>
<label for="newBrand">Brand:</label>
<input name="newBrand" type="text" placeholder="Brand Name" required>
</div>
<div>
<p>Location</p>
<label for="country">Country:</label>
<select name="country" id="" onchange="" required>
<option value="" disabled selected>Select Country</option>
<option value="US">US</option>
</select>
<label for="state">State/Province:</label>
<input name="state" type="text" placeholder="State or province" required>
<label for="city">City:</label>
<input name="city" type="text" placeholder="City" required>
<div>
<label for="businessType">Business Type:</label>
<select name="businessType" id="businessTypeSelect" onchange="businessOtherDisplay(this.value);" required>
<option value="" disabled selected>Select Request Reason</option>
<option value="americanDiner">American Diner</option>
<option value="pizzaParlor">Pizza Parlor</option>
<option value="coffeeShop">Coffee Shop</option>
<option value="candyShop">Candy Store</option>
<option value="iceCreamParlor">Ice Cream Parlor</option>
<option value="burgerShop">Burger Shop</option>
<option value="otherNon_AmericanDiner">Other non-American Diner (Foreign servings)</option>
<option value="other">Other (not listed above)</option>
</select>
</div>
<div id="businessTypeDisplay">
<label for="businessTypeOther">Business Type Other:</label>
<input name="businessTypeOther" type="text" placeholder="Business type if not listed above">
</div>
<div>
<label for="integration">Integration:</label>
<select name="integration" required>
<option value="" disabled selected>Select Request Reason</option>
<option value="square">Square</option>
<option value="clover">Clover</option>
<option value="cloverPilot">Clover Pilot</option>
<option value="stripe">Stripe</option>
<option value="gPay">GPAY</option>
<option value="others" >Others</option>
</select>
</div>
<label for="menuSource">File Attachment/Source:</label>
<input name="menuSource" type="text" placeholder="Path to menu" required url>
<div>
<p>Do you need an item hidden/disabled?</p>
<label for="yes">Yes</label>
<input name="disableItemOption" type="radio" value="yes" onclick="showItem()">
<label for="no">No</label>
<input name="disableItemOption" type="radio" value="no" checked onclick="hideItem()">
</div>
<div id="itemDisplay">
<label for="itemDisable">Which item(s) should be disabled?</label>
<textarea id="disabledItem" name="itemDisable" cols="40" rows="5"></textarea>
</div>
<div>
<p>Do you need a modifier hidden/disabled?</p>
<label for="yes">Yes</label>
<input name="disableModOption" type="radio" value="yes" onclick="showMod()">
<label for="no">No</label>
<input name="disableModOption" type="radio" value="no" checked onclick="hideMod()">
</div>
<div id="modDisplay">
<label for="modDisable">Which modifier(s) should be disbaled?</label>
<textarea id="disabledMod" name="modDisable" cols="40" rows="5"></textarea>
</div>
<div>
<p>Do you need to update a price?</p>
<label for="yes">Yes</label>
<input name="updatePrice" type="radio" value="yes" onclick="showPrice()">
<label for="no">No</label>
<input name="updatePrice" type="radio" value="no" checked onclick="hidePrice()">
</div>
<div id="priceDisplay">
<label for="priceUpdate">Which item/modifier needs a price update?</label>
<textarea id="updatedPrice" name="priceUpdate" cols="40" rows="5" priceUpdate></textarea>
</div>
<div>
<label for="otherUpdates">Any other information needed on the menu?</label>
<input name="otherUpdates" type="text" placeholder="List other instructions here">
</div>
<div>
<label for="specialInstructions">Are there special instructions/notes for this brand?</label>
<input name="specialInstructions" type="text" placeholder="List special instructions here">
</div>
<input id="submitButton" type="submit" value="Submit">
<input type="button" value="Cancel" onclick="google.script.host.close()">
</div>
</form>
<script>
function handleNewAccountFormSubmit(formObject) {
document.getElementById('submitButton').disabled=true;
google.script.run.withSuccessHandler().processNewAccountForm(formObject);
}
function disableSubmit() {
document.getElementById('submitButton').disabled=true;
document.getElementById('submitButton').value='Sending...';
}
function showItem(){
document.getElementById('itemDisplay').style.display ='block';
document.getElementById('disabledItem').required = true;
};
function hideItem(){
document.getElementById('itemDisplay').style.display = 'none';
document.getElementById('disabledItem').required = false;
};
function showMod(){
document.getElementById('modDisplay').style.display ='block';
document.getElementById('disabledMod').required = true;
};
function hideMod(){
document.getElementById('modDisplay').style.display = 'none';
document.getElementById('disabledMod').required = false;
};
function showPrice(){
document.getElementById('priceDisplay').style.display ='block';
document.getElementById('updatedPrice').required = true;
};
function hidePrice(){
document.getElementById('priceDisplay').style.display = 'none';
document.getElementById('updatedPrice').required = false;
};
function businessOtherDisplay(value) {
if(value === "other") {
document.getElementById('businessTypeDisplay').style.display = 'block';
} else {
document.getElementById('businessTypeDisplay').style.display = 'none';
};
};
</script>
</body>
</html>
And the code to handle the logic
function processNewAccountForm(formObject) {
const ui = SpreadsheetApp.getUi();
const ass = SpreadsheetApp.getActiveSpreadsheet();
const ss = ass.getActiveSheet();
const timestamp = Utilities.formatDate(new Date(), "GMT+8", "MM/dd/yyyy HH:mm:ss");
const userEmail = Session.getActiveUser().getEmail();
const brandName = formObject.newBrand;
// Add alert to check data entered is correct
const response = ui.alert('Please confirm the following information is correct:',
'ššæš®š»š± š”š®šŗš²: ' + formObject.newBrand +
'\nšš¼šš»ššæš: ' + formObject.country +
'\nš¦šš®šš²: ' + formObject.state +
'\nšš¶šš: ' + formObject.city +
'\nšššš¶š»š²šš š§šš½š²: ' + formObject.businessType +
'\nšš»šš²š“šæš®šš¶š¼š»: ' + formObject.integration +
'\nšš¶š¹š² š¦š¼ššæš°š²: ' + formObject.menuSource +
'\nšš¼ šš¼š š»š²š²š± š®š» š¶šš²šŗ šµš¶š±š±š²š»/š±š¶šš®šÆš¹š²š±?: ' + formObject.disableItemOption +
'\nšŖšµš¶š°šµ š¶šš²šŗ(š) ššµš¼šš¹š± šÆš² š±š¶šš®šÆš¹š²š±?: ' + formObject.itemDisable +
'\nšš¼ šš¼š š»š²š²š± š® šŗš¼š±š¶š³š¶š²šæ šµš¶š±š±š²š»/š±š¶šš®šÆš¹š²š±?: ' + formObject.disableModOption +
'\nšŖšµš¶š°šµ šŗš¼š±š¶š³š¶š²šæš ššµš¼šš¹š± šÆš² š±š¶šš®šÆš¹š²š±?: ' + formObject.modDisable +
'\nšš¼ šš¼š š»š²š²š± šš¼ šš½š±š®šš² š® š½šæš¶š°š²?: ' + formObject.updatePrice +
'\nšŖšµš¶š°šµ š¶šš²šŗ/šŗš¼š±š¶š³š¶š²šæ š»š²š²š±š š® š½šæš¶š°š² šš½š±š®šš²?: ' + formObject.priceUpdate +
'\nšš»š š¼ššµš²šæ š¶š»š³š¼šæšŗš®šš¶š¼š» š»š²š²š±š²š± š¼š» ššµš² šŗš²š»š?: ' + formObject.otherUpdates +
'\nššæš² ššµš²šæš² šš½š²š°š¶š®š¹ š¶š»šššæšš°šš¶š¼š»š/š»š¼šš²š š³š¼šæ ššµš¶š šÆšæš®š»š±?: ' + formObject.specialInstructions
, ui.ButtonSet.YES_NO);
if(response === ui.Button.YES) {
var lock = LockService.getScriptLock();
lock.waitLock(60000);
try {
const brandColumn = ss.getRange('D:D');
const brandValues = brandColumn.getValues();
let i = 1;
// Check for exisiting brand name
for(i=1; i < brandValues.length; i++) {
if(brandValues[i].toString().toLowerCase().trim() == brandName.toString().toLowerCase().trim() && ss.getRange(i+1,5).getValue() == 'New Brand'){
ui.alert("Brand name already created");
return;
}
};
// Create folder and PDF with build instructions
const parentFolder = DriveApp.getFolderById("RemovedfolderID");// how does this work with Shared drives? Create and move?
// const parentFolder = DriveApp.getFolderById("RemovedfolderID"); < ---- Team drive ID (notworking..) My folder -> RemovedfolderID
const newFolder = parentFolder.createFolder(brandName);
const docFile = newFolder.createFile(brandName+'.pdf',
'ššæš®š»š± š”š®šŗš²: ' + formObject.newBrand +
'\nšš¼šš»ššæš: ' + formObject.country +
'\nš¦šš®šš²: ' + formObject.state +
'\nšš¶šš: ' + formObject.city +
'\nšššš¶š»š²šš š§šš½š²: ' + formObject.businessType +
'\nšš»šš²š“šæš®šš¶š¼š»: ' + formObject.integration +
'\nšš¶š¹š² š¦š¼ššæš°š²: ' + formObject.menuSource +
'\nšš¼ šš¼š š»š²š²š± š®š» š¶šš²šŗ šµš¶š±š±š²š»/š±š¶šš®šÆš¹š²š±?: ' + formObject.disableItemOption +
'\nšŖšµš¶š°šµ š¶šš²šŗ(š) ššµš¼šš¹š± šÆš² š±š¶šš®šÆš¹š²š±?: ' + formObject.itemDisable +
'\nšš¼ šš¼š š»š²š²š± š® šŗš¼š±š¶š³š¶š²šæ šµš¶š±š±š²š»/š±š¶šš®šÆš¹š²š±?: ' + formObject.disableModOption +
'\nšŖšµš¶š°šµ šŗš¼š±š¶š³š¶š²šæš ššµš¼šš¹š± šÆš² š±š¶šš®šÆš¹š²š±?: ' + formObject.modDisable +
'\nšš¼ šš¼š š»š²š²š± šš¼ šš½š±š®šš² š® š½šæš¶š°š²?: ' + formObject.updatePrice +
'\nšŖšµš¶š°šµ š¶šš²šŗ/šŗš¼š±š¶š³š¶š²šæ š»š²š²š±š š® š½šæš¶š°š² šš½š±š®šš²?: ' + formObject.priceUpdate +
'\nšš»š š¼ššµš²šæ š¶š»š³š¼šæšŗš®šš¶š¼š» š»š²š²š±š²š± š¼š» ššµš² šŗš²š»š?: ' + formObject.otherUpdates +
'\nššæš² ššµš²šæš² šš½š²š°š¶š®š¹ š¶š»šššæšš°šš¶š¼š»š/š»š¼šš²š š³š¼šæ ššµš¶š šÆšæš®š»š±?: ' + formObject.specialInstructions,
MimeType.PDF);
const fileURL = docFile.getUrl();
// add header row to spreadsheet
// Create Spreadsheet in Brand folder. Activity log.
const name = brandName + " Activity Log";
const id = newFolder.getId();
const resource = {
title: name,
mimeType: MimeType.GOOGLE_SHEETS,
parents: [{id: id}]
};
const fileJson = Drive.Files.insert(resource);
const fileId = fileJson.id;
const lastRow = ss.getLastRow();
const newEntry = [
lastRow,
timestamp,
timestamp,
formObject.newBrand,
'New Brand',
formObject.businessType,
formObject.integration,
'=HYPERLINK("'+formObject.menuSource+'")',
userEmail,
fileURL,
,
,
,
,
formObject.city,
formObject.state,
formObject.country,
fileId
];
const newSheet = SpreadsheetApp.openById(fileId);
const sheetRange = newSheet.getSheetByName("Sheet1").getRange(1,1,1,18);
const headers = [
['šš»š±š²š
',
'ššæš®š»š± š¼šæš¶š“š¶š»š®š¹ š°šæš²š®šš² š±š®šš²',
'š§š¶šŗš² šš»',
'ššæš®š»š± š”š®šŗš²',
'š„š²š¾šš²šš šæš²š®šš¼š»',
'šššš¶š»š²šš ššš½š²',
'šš»šš²š“šæš®šš¶š¼š»',
'š š²š»š š¦š¼ššæš°š²',
'ššæš²š®šš²š± šÆš:',
'š š²š»š šš»šššæšš°šš¶š¼š»š',
'šššš¶š“š»š²š± šš¼?',
'š§š¶šŗš² š¢šš',
'šš¼šŗš½š¹š²š
š¶šš š„š®šš¶š»š“',
'šš¼ š¹š¶šš² š±š®šš² š®š»š± šš¶šŗš²',
'šš¶šš',
'š¦šš®šš²/š£šæš¼šš¶š»š°š²',
'šš¼šš»ššæš',
'šš°šš¶šš¶šš šš¼š“']
];
sheetRange.setValues(headers);
// Add data to last row in main tracker
ss.appendRow(newEntry);
// Copy data to spreadsheet brand
const activitySheet = newSheet.getSheetByName("Sheet1")
activitySheet.appendRow(newEntry);
// Flush changes before releasing lock
SpreadsheetApp.flush();
} catch(e) {
ui.alert("System is Busy, Please try again in a moment.");
return
} finally {
lock.releaseLock();
return
}
} else {
// action to take if info is incorrect? or No is clicked
};
};
I know that multiple triggers have been a known issue as per posts from Cooper and others here and here but I can't seem to be able to adopt them for my solution.
Thanks in advance for any ideas.
These are the changes I'd make to the dialog:
<input id="btn1" type="button" value="Submit" onClick="handleNewAccountFormSubmit(this.parentNode);" />
<input type="button" value="Cancel" onclick="google.script.host.close()">
</div>
</form>
<script>
function handleNewAccountFormSubmit(formObject) {
document.getElementById('btn1').disabled=true;
google.script.run.processNewAccountForm(formObject);
}
I'm not saying that your way is wrong. That's just the way I would try to do it. But realistically it's a fairly large dialog and your just going to have to dig in and figure it out. If I were doing it and I was having a lot of problems I'd probably start with a simpler version and get it to work and then slowly add more features.
This is actually a fairly difficult time two write code in the middle of a transition between two runtimes. I've just noticed that I've lost my content assist in some areas in ES5 but they now work in ES6 so things can be difficult to deal with.
I am currently doing a unit task and am having trouble working out why my javascript wont connect. i have tried a few things but cant seem to work it out. Im sure its easy but i just cant work it out. an explanation would be great too.
There are two files one html and one javascript.
Thanks in advance
HTML
<script src="validate.js"></script>
</head>
<body>
<header>
<h1>Rohirrim Ranch Tours</h1>
<h2>Booking Form</h2>
</header>
<form id="regform" method="post"
action="https://mercury.swin.edu.au/it000000/formtest.php"
novalidate="novalidate">
<fieldset id="person">
<legend>Your details:</legend>
<p><label for="firstname">Enter your first name</label>
<input type="text" name="firstname" id="firstname" size="20"
/>
</p>
<p><label for="lastname">Enter your last name</label>
<input type="text" name="lastname" id="lastname" size="20" />
</p>
<fieldset id="species">
<legend>Species:</legend>
<label for="human">Human</label>
<input type="radio" name="species" id="human"
value="Human"/><br />
<label for="dwarf">Dwarf</label>
<input type="radio" name="species" id="dwarf"
value="Dwarf" /><br />
<label for="elf">Elf</label>
<input type="radio" name="species" id="elf"
value="Elf" /><br />
<label for="hobbit">Hobbit</label>
<input type="radio" name="species" id="hobbit"
value="Hobbit" /><br />
</fieldset>
<p><label for="age">Enter your age</label>
<input type="text" id="age" name="age" size="5">
</p>
<p><label for="beard">Enter your beard length in inches</label><br />
0 <input type="range" id="beard" name="beard" min="0"
max="60"> 60
</p>
</fieldset>
<fieldset id="trip">
<legend>Your trip:</legend>
<fieldset>
<legend>Booking:</legend>
<label for="1day">1 Day Tour - $200 </label>
<input type="checkbox" name="1day" id="1day"
value="1day" /><br />
<label for="4day">4 Day Tour - $1500</label>
<input type="checkbox" name="4day" id="4day"
value="4day" /><br />
<label for="10day">10 Day Tour - $3000</label>
<input type="checkbox" name="10day" id="10day"
value="10day" /><br />
</fieldset>
<p>
<label for="food">Menu preferences</label>
<select name="food" id="food">
<option value="none">Please select</option>
<option value="lembas">Lembas</option>
<option value="mushrooms">Mushrooms</option>
<option value="ent">Ent Draft</option>
<option value="cram">Cram</option>
</select>
</p>
<p>
<label for="partySize">Number of Travellers</label>
<input type="text" id="partySize" name="partySize"
maxlength="3" size="3" />
</p>
</fieldset>
<div id="bottom"> </div>
<p><input type="submit" value="Book Now!" />
<input type="reset" value="Reset" />
</p>
</form>
JAVASCRIPT
"use strict";
function validate() {
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;
var errMsg = "";
var result = true;
if (!firstname.match(/^[a-zA-Z]+$/)) {
errMsg = errMsg + "Your first name must only contain alpha
characters\n";
result = false; }
if (!lastname.match(/^[a-zA-Z+$]/)){
errMsg = errMsg + "Your last name must only contain alpha
characters\n";
result = false;
}
var age = document.getElementById("age").value;
if (isNaN(age)){
errMsg = errMsg + "your age must be a number\n"
result = false;
}
else if (age < 18) {
errMsg = errMsg +" your age must be 18 or older\n";
result = false;
}
else if (age >= 10000) {
errMsg = errMsg + "your age must be between 18 and 10000\n";
result = false;
}
var partySize = document.getElementById("partySize").value;
if (isNaN(partySize)) {
errMsg = errMsg + "your age must be a number\n"
result = false;
}
else if (partySize < 1) {
errMsg = errMsg +" party size must be greater than 0\n";
result = false;
}
else if (age >= 100) {
errMsg = errMsg + "your party size must be less or equal to 100\n";
result = false;
}
if (erMsg !== ""){
alert(errMsg);
}
return result;
}
function init() {
var regForm = document.getElementById("regform");
regForm.onsubmit = validate;
}
window.onload = init;
I see your error erMsg instead of errMsg
if (erMsg !== ""){
alert(errMsg);
}
and also add event.preventDefault(); at the beginning of the validate function
Your js reference is fine :)
Try setting the Javascript url as './validate.js'