Open 3 different google searches by one click - javascript

I´m looking for a way to run three google searches with three different keywords by one click.
Here´s what I got so far:
<form action="https://google.com/search" method="get" target="_blank">
<input type="text" id="q1" name="q" placeholder="first" required /><br>
<input type="text" id="q2" name="q" placeholder="second" required /><br>
<input type="text" id="q3" name="q" placeholder="third" required /><br>
<input type="submit" value="Google Search" />
</form>
It opens a new tab with a google search for all three keywords.
But I want it to open three different tabs/sites/frames... each one with a search for one keyword. I guess there´s a way to solve this problem with js but I know almost nothing about java script.
I need something like:
onsubmit = window.open("search1"); window.open("search2"); window.open("search3");
Hope you can help me.
Greetz

function openNewTab(url){
var redirectWindow = window.open(url, '_blank');
redirectWindow.location;
}
document.getElementById("asd").addEventListener("click", submit);
function submit(){
var a = document.getElementById('q1').value;
var b = document.getElementById('q2').value;
var c = document.getElementById('q3').value;
var url = "http://google.com/search?q=";
openNewTab(url+a);
openNewTab(url+b);
openNewTab(url+c);
}
<form>
<input type="text" id="q1" name="q" placeholder="first" required /><br>
<input type="text" id="q2" name="q" placeholder="second" required /><br>
<input type="text" id="q3" name="q" placeholder="third" required /><br>
<input type="submit" id="asd" value="Google Search" />
</form>
Well this is entirely based on user's browser settings whether he allows to open new tabs by scripts or not. Above code will only work if Popups are allowed in browser. I see no other way to sort it out
To test on your browser (Assume you're running chrome) , you can change settings here chrome://settings/content/popups in your browser and allow popups

I´ve got a solution... not very elegant but it works (sort of).
<form id="form1" action="https://google.com/search" method="get" target="_blank">
<input type="text" id="q1" name="q" placeholder="first" required /></form><br>
<form id="form2" action="https://google.com/search" method="get" target="_blank">
<input type="text" id="q2" name="q" placeholder="second" required /></form><br>
<form id="form3" action="https://google.com/search" method="get" target="_blank">
<input type="text" id="q3" name="q" placeholder="third" required /></form><br>
<button onclick="document.getElementById('form1').submit();
document.getElementById('form2').submit();
document.getElementById('form3').submit();"> Search </button>

Related

Javascript alert not working on website

I have tried several different things in javascript but nothing seems to work on my site. I'm trying to have an alert pop up when submitting a form. This is what I have
<form>
Name:<br>
<input type="text" name="name" required><br>
Email:<br>
<input type="email" name="email" required><br>
Phone (Format: 999-999-9999):<br>
<input type="tel" name="phone" required pattern="\d{3}[\-]\d{3}[\-]\d{4}"><br>
Nature of comment:<br>
<input type="checkbox" name="comment" value="Question"> Question
<input type="checkbox" name="comment" value="Business Inquiry"> Business Inquiry
<input type="checkbox" name="comment" value="Comment"> Comment
<input type="checkbox" name="comment" value="Other"> Other <br>
Comment:<br>
<textarea></textarea><br>
<input type="submit" value="Submit">
<form onsubmit="return confirm('Do you really want to submit the form?');">
</form>
This is the website: http://webpages.uncc.edu/~kjardine/MC_Portfolio/contact.html
You were almost there, the key is the code you have already has a <form> tag which starts on line 1, so you should add your onsubmit="" attribute into that one. Here is the revised code that should do the trick:
<form onsubmit="return confirm('Do you really want to submit the form?');">
Name:<br>
<input type="text" name="name" required><br>
Email:<br>
<input type="email" name="email" required><br>
Phone (Format: 999-999-9999):<br>
<input type="tel" name="phone" required pattern="\d{3}[\-]\d{3}[\-]\d{4}"><br>
Nature of comment:<br>
<input type="checkbox" name="comment" value="Question"> Question
<input type="checkbox" name="comment" value="Business Inquiry"> Business Inquiry
<input type="checkbox" name="comment" value="Comment"> Comment
<input type="checkbox" name="comment" value="Other"> Other <br>
Comment:<br>
<textarea></textarea><br>
<input type="submit" value="Submit">
</form>
The onsubmit should go in the form element at the top, like the commenter said. and the form element its in currently should be deleted.
That said, you could also have checked a "dont show any more popups" option once for that website, and now popups will be disabled until you enable the popups again, by clearing your chrome cache for instance.
<form onsubmit="return confirm('u sure?');">
<input>...
</form>
I also advise against using onsubmit as an HTML parameter, and instead writing a js handler in an actual <script></script block to do the confirm.
window.onload = function () {
document.getElementById("myForm").onsubmit = function onSubmit(form) {
return confirm('u sure?');
}
}
Remember to add id="myForm" to your form element in this case.

form not posting to iframe back

This should have been pretty simple but I have spent a few hours trying to figure out why a simple form post would not end up in the iframe instead of a new window.
I am trying to post data to authorize.net and I want the reponse to be back in the iframe. However it opens a new window. I am not sure what else to do. here is my code
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
document.getElementById("test-form").submit();
});
</script>
</head>
<body>
<form method="post" name="test-form" id="test-form" target="myIframe" action="https://test.authorize.net/gateway/transact.dll">
<input type="text" name="x_login">
<input type="text" name="x_fp_sequence">
<input type="text" name="x_fp_timestamp">
<input type="text" name="x_amount">
<input type="text" name="x_fp_hash">
<input type="text" name="x_show_form">
<input type="text" name="x_test_request">
<input type="text" name="x_type">
<input type="text" name="x_currency_code">
<input type="text" name="x_invoice_num">
<input type="text" name="x_description">
<input type="text" name="x_first_name">
<input type="text" name="x_last_name">
<input type="text" name="x_company">
<input type="text" name="x_address">
<input type="text" name="x_city">
<input type="text" name="x_state">
<input type="text" name="x_zip">
<input type="text" name="x_country">
<input type="text" name="x_phone">
<input type="text" name="x_email">
<input type="text" name="x_relay_response">
<input type="text" name="x_solution_id">
</form>
<iframe src="" name="myIframe></iframe>
</body>
</html>
By putting your code in Plunker, there is a syntax error at line 37:
<iframe src="" name="myIframe></iframe>
^-- missing "
After adding the closing quote, I can see the page loaded in the iFrame :)
https://embed.plnkr.co/aM5EsESHODV8nPbVhyK8/
You may want to consider changing to use an IDE which may help you identifying typos, so that hours can be saved.
You are missing double quotes at the end of the iframe name.

Password validation (2 Textboxes, comparision)

before you blame me, yes I was looking for something similar for about a hour, but sadly I couldn't find my error, atleast the Questions I was looking for in stackoverflow didn't gave me a correct answere, as I have almost exactly the same thing (not Copy and Paste).
However could someone explain me, why my code (javascript) isn't working?
I am playing around with it for some hours now but I can't find it.
<html>
<head>
<title>Anmeldung/Login</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script>
function abc(){
var a = document.getElementById('pw').value;
var b = document.getElementById('repw').value;
if(a==b){
alert(yes)
}
}
</script>
</head>
<body>
<div id="banner">
<p>NAME/ÜBERSCHRIFT</p>
</div>
<form id="loginpanel">
<fieldset>
<legend>LOGIN</legend>
<p class="textinput">Benutzername: <input name="id" type="text" size="30" maxlength="30"></p>
<p class="textinput">Passwort: <input name="pw" type="password" size="30" maxlength="15"></p>
<input class="button" type="button" name="login" value="Anmelden"/>
</fieldset>
</form>
<p id="option"> ...oder Registrieren!</p>
<form id="registerpanel">
<fieldset>
<legend>REGISTER</legend>
<p class="textinput">Benutzername: <input name="id" type="text" size="30" maxlength="30"></p>
<p class="textinput">eMail: <input name="email" type="text" size="30" maxlength="30"></p>
<p class="textinput">Passwort: <input name="pw" type="password" size="30" maxlength="30"></p>
<p class="textinput">Passwort wiederholen: <input name="repw" type="password" size="30" maxlength="30"></p>
<input class="button" type="button" onclick="abc()" name="register" value="Registrieren"/>
</fieldset>
</form>
</body>
I would be happy if someone can give me an answere!
Thank you for taking your time :)!
You must have inputs with id attribute with values pw+repw. Having only a name attribute will not work
example: <input name="repw" id="repw" type="password" size="30" maxlength="30">
Corrected version (only relevant parts):
<script>
window.abc = function(){
var a = document.getElementById('pw').value;
var b = document.getElementById('repw').value;
if(a==b){
alert("yes")
}
}
</script>
...
<form id="registerpanel">
<fieldset>
<legend>REGISTER</legend>
<p class="textinput">Benutzername: <input name="id" type="text" size="30" maxlength="30"></p>
<p class="textinput">eMail: <input name="email" type="text" size="30" maxlength="30"></p>
<p class="textinput">Passwort: <input name="pw" id="register-pw" type="password" size="30" maxlength="30"></p>
<p class="textinput">Passwort wiederholen: <input name="repw" id="register-repw" type="password" size="30" maxlength="30"></p>
<input class="button" type="button" onclick="abc()" name="register" value="Registrieren"/>
</fieldset>
</form>
Note the added IDs. I didn't do pw and repw because having plain pw in login made more sense to me (11684) (don't forget to add that in the login form). Because I'd do register-pw I went for consistency and did register-repw. But it doesn't matter what these IDs are as long as they are unique.
And I changed the typo alert(yes) into alert("yes") because obviously the first throws a reference error.
A working JSFiddle: http://jsfiddle.net/7NZUc/

Passing form data from one page to another html mobile page

I'm new to mobile development and I am trying to pass information from a form and I want to display it on another page. I have tried passing the info using cookies but with no success..
Here is my code for the form:
function submit_jobs_post(){
$.cookie('job_title', $('#job_title').val());
$.cookie('job_des', $('#job_des').val());
$.cookie('company_name', $('#company_name').val());
$.cookie('company_address', $('#company_address').val());
$.cookie('company_phone', $('#company_phone').val());
$.cookie('company_email', $('#company_email').val());
}
<form method="post" action="jobs_page.html" id="post_ads">
<label for="job_title">Job Title:</label>
<input type="text" name="job_title" id="job_title">
<label for="job_des">Job Description:</label>
<textarea name="job_des" id="job_des"></textarea>
<label for="company_name">Company Name:</label>
<input type="text" name="company_name" id="company_name">
<label for="company_address">Address:</label>
<input type="text" name="company_address" id="company_address">
<label for="company_phone">Phone:</label>
<input type="text" name="company_phone" id="company_phone">
<label for="company_email">Email:</label>
<input type="email" name="company_email" id="company_email" placeholder="Your email..">
<input type="submit" data-inline="true" value="Post Job" onClick='submit_jobs_post()'>
</form>
And here is my code for the page to receive the information. When I submit the form the data does not appear on this page.
window.onload = function()
{
$('#job_title_got').val($.cookie('job_title'));
$('#job_des_got').val($.cookie('job_des'));
$('#company_name_got').val($.cookie('company_name'));
$('#company_address_got').val($.cookie('company_address'));
$('#company_phone_got').val($.cookie('company_phone'));
$('#company_email_got').val($.cookie('company_email'));
};
<input type="text" name="job_title_got" id="job_title_got">
<textarea name="job_des_got" id="job_des_got"></textarea>
<input type="text" name="company_name_got" id="company_name_got">
<input type="text" name="company_address_got" id="company_address_got">
<input type="text" name="company_phone_got" id="company_phone_got">
<input type="email" name="company_email_got" id="company_email_got" >
Any help would be great, thanks in advance...

IFrame form submittal opens in frame, needs to open in new window

Trying to resolve an issue using a 3rd party form that unfortunately has to use an iframe to be embedded in the article content. When a user submits their email address, the thank you page opens up in the space taken up by the iframe instead of the page / a new window. I tried using the following JS script to no avail:
<script type="text/javascript">
// If "&_parent=URL" is in this page's URL, then put URL into the top window
var match = /_parent=(.+)/.exec(window.location.href);
if (match != null) {
top.location = match[1];
}
</script>
The page in question:
http://restoringqualityoflifeblog.org/subscribe/
Thanks!
From https://help.salsalabs.com/entries/21689130-Embed-a-signup-form
Here is the form you need by itself with [] indicating the keys you need for it to work.
<form action="[[API URL]]/save" method="POST">
<input type="hidden" name="organization_KEY" value="5881"/>
<input type="hidden" name="chapter_KEY" value="887"/>
<input type="hidden" name="email_trigger_KEYS" value="12644,12656"/>
<input type="hidden" name="object" value="supporter"/>
<label for="first_name">First Name:</label><input type="text" id="first_name" name="First_Name"/></br>
<label for="last_name">Last Name:</label><input type="text" id="last_name" name="Last_Name"/></br>
<label for="email">Email:</label><input type="text" id="email" name="Email"/></br>
<style>.memberCode{display:none;}</style>
<div class="memberCode"> Optional Member Code <input name="first_name_949" value=""/></div>
<input type="hidden" name="link" value="groups"/>
<input type="hidden" name="linkKey" value="11"/>
<input type="hidden" name="link" value="groups"/>
<input type="hidden" name="linkKey" value="12"/>
<input type="hidden" name="link" value="groups"/>
<input type="hidden" name="linkKey" value="13"/>
<input type="hidden" name="tag" value="excellent"/>
<input type="hidden" name="redirect" value="http://YOUR URL">
<input type="Submit" value="Sign up" />
</form>
You already have a working copy of the form here:
http://salsa3.salsalabs.com/o/50047/p/salsa/web/common/public/signup?signup_page_KEY=8896

Categories

Resources