Passing a parameter in a URL from HTML - html

First off, let me beg forgiveness for being such a noob at web development. I have looked everywhere for how to do this and can't find anything that tells me specifically.
Here is my link:
<td><a style="color:red;text-align:left" href=/sponsor/manageuser.htm?user="
+ target=_self"</a></td>
I need the parameter "user" to be appended and I also need the exact same value as user as the link. Like this:
<td><a style="color:red;text-align:left"
href=/sponsor/manageuser.htm?user="12345" 12345</a></td>
The problem is that I have to put the param and the link inside the tag. At least I think that's the problem So you click on 12345 link, it appends 12345 to the URL and passes it as a GET method. My form is a GET:
<form class="frm" method="get" name="currentusers" id="currentusers"
action="currentusers.htm">
And then here's what my URL looks like and of course I get a 404 error:
http://localhost:8080/sponsor/manageuser.htm?user=target=
Any advice is appreciated in advance.

jQuery way:
What you can do is have each link call a function and pass the value of the link into the function. The function append() will then add a hidden input value with the number you clicked on. Finally, the function will submit the form to the manageuser.htm page with the "?user=1234" as you requested.
You can see how the code works by copying and pasting this code and opening it on your computer.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form id = "form1" method="get" action="sponsor/manageuser.htm">
<table>
<tr>
<td><button id="1543" onclick="append(1543)">1543</button></td>
<td><button id="3515" onclick="append(3515)">3515</button></td>
<td><button id="1115" onclick="append(1115)">1115</button></td>
</tr>
</table>
</form>
<script>
function append(user_number)
{
$('<input />').attr('type', 'hidden').attr('name', "user").attr('value', user_number).appendTo('#form1');
$('#form1').submit();
}
</script>
</body>
</html>

Related

how to call GAS functions in local html page

to demonstrate what im trying to do using a simple example:
<html>
<head>
<base target="_top">
</head>
<body>
<form id="uploaderForm" action="https://script.google.com/macros/.......exec Method="POST">
<input type="text" name="applicantName" id="applicantName">
<input type="text" name="applicantEmail" id="applicantEmail">
<input type="button" value="Submit">
</form>
<script>
.
.
.
google.script.run.withSuccessHandler(onFileUploaded)
.uploadFile(content, file.name, folderId);
</script>
so this is an example of the html and js page that is in my pc, not in the google app, i just called the google app in the form, and in the javascript part im calling a function called uploadFile, which is located in the google script, but obviously i get an error in the console , it says :
Uncaught ReferenceError: google is not defined
at uploadFiles (6166bff606ac6fee1994e592:67)
at HTMLInputElement.onclick
is it possible to call a GAS function inside JS that is not in the GAS html.
is what im trying to do even possible, the whoel reason im doing this is so that i can pass the username and email automatically from the database to the app, the app works if the html part is hosted in the google app script, but then i cant figure out how to pass the email and username to it because in this case i call the app using , so is it possible to pass the username and email through the iframe call, i dunno im very new to this i have so many questions, honestly the documentation wasn't helpful to me. please feel free to comment anything, everythign is helpful
Since you're just posting the form data, you can name the function you want to call as doPost()(instead of uploadFile) and it will receive the posted data. You have to republish the webapp as a new version after the modification.
I just ran it as a dialog. I returned the data back into the success handler and loaded by into the html to insure it was working.
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<body>
<form>
<input type="text" name="applicantName" id="applicantName"/>
<input type="text" name="applicantEmail" id="applicantEmail"/>
<input type="button" value="Submit" onclick="uploadfile(this.parentNode);" />
</form>
<div id="msg"></div>
<script>
function uploadfile(form) {
google.script.run
.withSuccessHandler((m) => document.getElementById("msg").innerHTML = m)
.uploadMyFile(form);
}
</script>
</body>
</html>
gs:
function uploadMyFile(obj) {
return `Applicant Name: ${obj.applicantName}<br />Applicant Email: ${obj.applicantEmail}`;
}
function launchFormDialog() {
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah2'),'Test Dialog');
}
Dialog:

Send a form without the "?" character and the name of the value

I have this code:
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="https://api.pagar.me/1/zipcodes/">
<input type="text" placeholder="cep" name="cep">
<input type="submit">
</form>
</body>
</html>
When I type a number, for example 05423110, I get on the adress bar is "https://api.pagar.me/1/zipcodes/?cep=05423110", but I would like to have "https://api.pagar.me/1/zipcodes/05423110".
What do I need to change on my code?
Thanks!
I would do it like this. The other answer will have the problem where it could potentially append something twice.
I also set it so the button disables for user friendliness (in case the server takes awhile to respond).
This solution does use jQuery, but chances are you will need to do other simple DOM manipulation and this will be very helpful.
Because you don't want the query string in there, but you must have it be GET, then its impossible not to have it append the query string to the URL (because that's what a GET request does).
Instead, I use javascript to simply redirect to the proper URL and ignore the form GET/POST entirely.
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="https://api.pagar.me/1/zipcodes/">
<input type="text" placeholder="cep" name="cep">
<input type="submit">
</form>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
(function() {
var form = $('form');
var baseUrl = form.attr('action');
$('form').submit(function(e) {
e.preventDefault();
form.find('[type="submit"]').prop('disabled', true);
window.location.href = baseUrl + form.find('[name="cep"]').val();
});
})();
</script>
Add method="post" to the form tag, then add an event listener to the form's submit event which append the input value to the action attribute value on the form:
const form = document.forms[0]
form.addEventListener('submit',()=>{form.action+=cep.value})
<form action="https://api.pagar.me/1/zipcodes/" method="post">
<input type="text" placeholder="cep" name="cep" id="cep">
<input type="submit">
</form>
Ofc StackOverflow snippets prevents POST.

Click a html tag, then invoke the smarty function

I have a Smarty templte.
in its php file I registered a block function:
function test1($args){
$str="";
for($i=0;$i<$args['times'];$i++){
$str.="<font color='".$args['color']."' size='".$args['size']."'>".$args['con']."</font>"."<br>";
}
return $str;
}
// register block function
$smarty->registerPlugin('block' ,'hsp', 'test1');
and in the template:
<html>
<head>
<title>{$title}</title>
</head>
<body>
<button>
Click me
</button>
{hsp times="1" size="5" color="green" con="hello,world"}
{/hsp}
</body>
</html>
I have two questions,
why I access the smarty file there gets two hello,world?
{hsp times="1" size="5" color="green" con="hello,world"}
{/hsp}
you see there is only 1 times.
2.I want to click the button, then I invoke the function, how to realize this?

Store value in session variable in java script function on button click

I want to store rating value in jsp session variable inside the java script function for using in testOpeartion page
I tried this way but not storing any value "UserRating" session variable
<html>
<head>
<title>Registration Page</title>
<script type="text/javascript">
function SetRating()
{
var rating = document.getElementById("ratingValue").value;
<%
request.setAttribute("UsaerRating",rating);
%>
}
}
</script>
</head>
<body>
<form method="post" action="testOperation">
<input type="text" id="ratingValue" onclick="doDisplay(this);" />
<input type="Button" onclick="SetRating();" value="Set Rating"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
From this link
It's not possible to set any session variables directly from
javascript as it is purely a client side technology. You can use AJAX
though to asyncronously send a request to a servlet running on the
server and then add the data to the session from within the servlet.
So you wouldn't be using javascript to do the actual setting of
session variables but it would look like it is.
You can also get more details from THIS LINK

html form, newbie error

I have two html files namely "file1.html" and "file2.html". File1 is supposed to encode a string written in an input file and send it to file2 via URL so that it could be decoded there.
My problem is an embarrassing one as I'm having trouble while passing from file1 to file2. Here is my code:
<html>
<head>
<script type="text/javascript">
function encode()
{
var encodeThis = document.getElementById("exampleText").value;
document.getElementById("exampleText").value = escape(escape(encodeThis));
}
</script>
</head>
<body>
<form name="input" action="file2.html" method="get">
<input id="exampleText" type="text" name="example" value="Not strongly encoded" />
<input type="button" value="Encode and Submit!" onclick="encode()" />
</form>
</body>
</html>
When I click to submit button, I expect to send the encoded string via URL and pass to file2.html where I can process it, however I remain at my first page: "file1.html". Which fundamental knowledge do I lack here ? Thanks in advance for your time.
Because there is no submit. Either you give the input-tag the type submit instead of button or you make a form.submit () via JS.
document.input.submit(); should do this.
BTW... why double-escape?
The submit button should be like this:
<input type="submit" value="Encode and Submit!" onclick="encode()" />