I am trying to make a searh bar linking up to google.no (norway). when you search for music you get this URL: https://www.google.no/#q=music&*. My question is how i can get the (& *) at the end of a search.
.search {
border: solid 1px grey;
border-radius: 3px;
padding: 10px;
padding-left: 30px;
padding-right: 30px;
font-size: 15px;
margin: 15px;
}
<form class="form" action="http://www.google.no/#q=">
<input class="search" name="q" placeholder="Search...">
</form>
You cannot submit to this Google page, because it has an anchor # in it. This means, it has not the regular GET format, you would get, if you just submit a form to this URL. You have to calculate the correct URL in JavaScript or on the back-end side.
If you want to create the correct URL with JavaScript, you can use the function encodeURIComponent(url) to escape the parameter.
Here is an example:
var searchBox = document.querySelector('.search');
var form = document.querySelector('.form');
form.addEventListener('submit', function(event) {
var value = searchBox.value;
var escapedValue = window.encodeURIComponent(value);
var url = "https://www.google.no/#q=" + escapedValue
alert(url);
window.location.href = url;
event.preventDefault();
});
<form class="form" action="test">
<input class="search" name="q" placeholder="Search...">
<input type="submit" class="submit" value="Submit">
</form>
Related
How can I use a tag as submit button in my form (Is just matter of design for me and not functionality)
My form
<form action="{{route('wishlist.store')}}" method="post">
{{csrf_field()}}
<input type="text" name="user_id" value="{{Auth::user()->id}}" hidden>
<input type="text" name="product_id" value="{{$product->id}}" hidden>
<button type="submit" class="wish-list">
<i class="fas fa-heart"></i>
</button>
</form>
All the issue I have is that gray box behind my font icon which is caused by <button> so I need to use <a> tag.
I also tried to change my button with a tag and added something like:
$(document).on("click","#sendwish",function(){
$('form').submit(function(evt){
evt.preventDefault();
var url = $('form').attr("action");
var formData = $('form').serialize();
$.post(url, formData, function(response){
console.log(response);
});
});
});
but it didn't work.
any idea?
Perhaps you can just overwrite default styles on the button?
.wish-list {
background: none;
border: none;
padding: 0;
margin: 0;
}
or if need be:
<button style="background: none; border: none; padding: 0; margin: 0;"></button>
Give your a form an ID as well as the link and call the onclick function to then submit the form.
Let's say you have a form called with an ID of SubmitMe and a span / div with the ID of ClickMe.
Example:
document.getElementById("#ClickMe").onclick = function(){
document.getElementById("#SubmitMe").submit();
}
Just so you know this, this will submit what ever is the action on the "SubmitMe" form.
I'm trying to create a custom form in order to send one value (ID) and below of the form see the search result based on the input field.
For example: Complete the form and below see the search result in a DataBase (Google Sheets)
I saw some examples but I don't know how to get the value of the input field and use it with the Google Apps Script code (in order to search the ID in the rows).
Here some code I was trying:
code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function obtenerId() {
var email = Session.getActiveUser().getEmail();
var idtest='Juan';
return messageSecret_(idtest);
}
function messageSecret_(urldoc) {
return 'test'+urldoc;
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess(balance) {
var div = document.getElementById('output');
var idtest = document.getElementById('ingresoid').value;
div.innerHTML = balance+' '+idtest;
}
</script>
</head>
<body>
<!--Modificar texto de la aplicación -->
<p style="margin-bottom: 16px; font-family: 'Verdana regular'; font-size: 16px;color: #727277;line-height: 16px;text-align: justify;">Ingrese ID:
<br><br></p>
<input type="textbox" id="ingresoid" size="20">
<br><br>
<input type="button" value="Enviar respuesta" onclick="google.script.run.withSuccessHandler(onSuccess)
.obtenerId();" style="background-color:#C1D72E;border-radius:10px;padding:5px;color: #fff; border-color: #C1D72E;"
/><br>
<br>
<div id="output"></div>
</body>
</html>
How about the following modification?
From:
<input type="textbox" id="ingresoid" size="20">
<br><br>
<input type="button" value="Enviar respuesta" onclick="google.script.run.withSuccessHandler(onSuccess)
.obtenerId();" style="background-color:#C1D72E;border-radius:10px;padding:5px;color: #fff; border-color: #C1D72E;"
/><br>
To:
<form> <!-- Added -->
<input type="textbox" id="ingresoid" size="20" name="sample"> <!-- Modified -->
<br><br>
<input type="button" value="Enviar respuesta" onclick="google.script.run.withSuccessHandler(onSuccess)
.obtenerId(this.parentNode);" style="background-color:#C1D72E;border-radius:10px;padding:5px;color: #fff; border-color: #C1D72E;"
/><br> <!-- Modified -->
</form> <!-- Added -->
After modified, the inputted value can be retrieved at GAS side as follows.
function obtenerId(e) {
var value = e.sample;
}
I am making a thing for setting goals,and to show your progress, I use the progress element. I would like to save my goal with php/js/other to a .txt file on my server called user.txt. I have already tried this Write server text files with Ajax and PHP write file from input to txt shows what I want, but instead of form tags, I want just 2 input fields
Is there any way I can merge these 2 files to save my data from my 2 fields to a text file(user.txt)
Here is my code:
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("myProgress").value = x;
}
function myFunction2() {
var x = document.getElementById("myTextarea2").value;
document.getElementById("myProgress").max = x;
}
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 30em;
height: 3em;
border: 1px solid #0063a6;
background: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h3>Goal Progress:</h3>
<progress id="myProgress" value="0" max="100">
</progress>
<hr>
<input type="text" id="myTextarea"></input>
<button onclick="myFunction()">Add</button>
<hr>
<input type="text" id="myTextarea2" />
<button onclick="myFunction2()">Set Goal</button>
<hr>
here I finally solved my perplexing paradyme:
<html>
<body onload="timer=setTimeout('myFunction2(); myFunction();',3000)">
<style>
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 30em;
height: 3em;
border: 1px solid #0063a6;
background: #fff;
}
</style>
<h3>Goal Progress:</h3>
<progress id="myProgress" value="0" max="100">
</progress>
<hr>
<form action="form.php" method="POST">
add money:
<input type ="text" name="field1" id="myTextarea"></input>
<hr>
Goal:
<input type ="text" name="field2" id="myTextarea2"/>
<input type="submit" name="submit" value="Save Data">
</form>
<hr>
<button onclick="myFunction2(); myFunction();">show new progress</button>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("myProgress").value = x;
}
function myFunction2() {
var x = document.getElementById("myTextarea2").value;
document.getElementById("myProgress").max = x;
}
</script>
</body>
</html>
Put together this script that will upload a file to my google drive.
I need it to be able to handle either a big .zip file, OR multiple image files.
Currently it times out if you upload a big .zip file (around 7MB)
I would prefer to have it upload multiple files.
Apps Script:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var unitNumber = form.unitNumber;
if (unitNumber == "") {
unitNumber = "";
} else {
unitNumber = " #" + unitNumber;
}
var foldertitle = form.streetAddress + unitNumber + ' ' + form.cityName + ' ' + form.stateName + ' - ' + form.businessName + ' ' + form.managerName + ' - ' + form.propertyType;
var folder, folders = DriveApp.getFolderById("0B0V8-0eo7tx8MTQzcGFwdXF6SFU");
var createfolder = folders.createFolder(foldertitle);
folder = createfolder;
var blob = form.filename;
var file = folder.createFile(blob);
return "File uploaded successfully ";
} catch (error) {
Logger.log('err: ' + error.toString());
return error.toString();
}
}
Form Code
<body>
<div id="formcontainer">
<form id="myForm">
<div>
<input type="text" name="businessName" placeholder="Business Name">
</div>
<div>
<input type="text" name="managerName" placeholder="Manager Name">
</div>
<div>
<input type="text" name="streetAddress" placeholder="Street Address">
</div>
<div>
<input type="text" name="unitNumber" placeholder="Unit Number">
</div>
<div>
<input type="text" name="cityName" placeholder="City">
</div>
<div>
<input type="text" name="stateName" placeholder="State">
</div>
<br>
<label for="propertyType">Choose Type</label>
<br>
<select name="propertyType">
<option value="Interactive Floor Plan">IFP</option>
<option value="Pictures Only">Pictures</option>
<option value="Video Only">Video</option>
<option value="Complete Property">All</option>
</select>
<br>
<label for="myFile">Compress All Files into .zip file</label>
<br>
<input type="file" name="filename" id="myFile" multiple>
<input type="submit" value="Upload File" onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
</div>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
body {
max-width: 400px;
padding: 20px;
margin: auto;
}
input {
display: inline-block;
width: 100%;
padding: 5px 0px 5px 5px;
margin-bottom: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
select {
margin: 5px 0px 15px 0px;
}
input[type="submit"] {
width: auto !important;
display: block !important;
}
input[type="file"] {
padding: 5px 0px 15px 0px !important;
}
</style>
</body>
I don't see other way to make GAS work with multiple files if not with multiple files inputs. You can add dinamically input with Jquery (or plain Javascript), and test in the server side to check how many input files got carried over.
Like so:
in HTML:
<input type="file" name="filename0" id="myFile"><div id="moreInputs"></div>
<button onClick="moreFieds()">Add more Fieds</button>
<script>
var numInputs = 1;
function moreFieds(){
$('#moreInputs').append($('<input type="file" name="filename'+numInputs+'" id="myFile">'));
numInputs++;
}
</script>
In code.gs:
var numForms = 0;
while( form[ (filename + numForms) ] ){
var blob = form[ (filename + numForms) ];
var file = folder.createFile(blob);
numForms++;
}
Or as I like more, send files inputs one by one in the script, giving each input it's own form, that way you can know when each file has done loading with the successHandler.
I used toggle to make a search form from a button. But I want click outside any position to close search form, not only using button.
HTML
Search
<div class="search_field" style="display:none;">
<form>
<input name="search" class="search" value="" placeholder="Search Item...." type="text" data-theme="e" />
<input type="submit" value="Search" data-mini="false" data-icon="search" data-iconpos="notext" data-theme="c" />
</form>
</div>
Jquery :
$(function() {
$(".opensearch").on('click', tapHandler);
function tapHandler(event) {
$('.search_field').toggle();
$('.search').focus();
}
});
Demo of JsFiddle
Many thanks for your help.
Use the blur event:
$(".search").on("blur",function(){
$('.search_field').toggle();
});
Updated fiddle: JsFiddle demo
[Edit] You might want to check if the new focus is not on the search icon before hiding the field:
$(".search").on("blur",function(){
setTimeout(function(){
var target = document.activeElement;
target = target ? target.id||target.tagName||target : '';
if(target!="INPUT"){
$('.search_field').toggle();
}
}, 1);
});
Better with the id of the button though....
Example: JsFiddle demo
You can do something like
$(function() {
$(".opensearch").on('click', tapHandler);
//add a click handler to the document object
$(document).on('click', function(e) {
//if the click is happening inside the search_field or opensearch elements then don't do anything
if ($(e.target).closest('.search_field, .opensearch').length == 0) {
$('.search_field').hide();
}
});
function tapHandler(event) {
$('.search_field').toggle();
$('.search').focus();
}
});
.search_field {
padding: 10px 10px 0;
position: relative;
}
.search_field .ui-submit {
bottom: -2px;
position: absolute;
right: 18px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Search
<div class="search_field" style="display:none;">
<form>
<input name="search" class="search" value="" placeholder="Search Item...." type="text" data-theme="e" />
<input type="submit" value="Search" data-mini="false" data-icon="search" data-iconpos="notext" data-theme="c" />
</form>
</div>