Link user input with login button - javascript

I would like to create a sort of login page. Which links to a href depending on the input of the user.
So i have a text input part and a login button.
Then it should go to the website depending on the text input.
Example: users fills in 1234 and clicks on the login button, then the website:
example.com/1234 opens up.
I tried but i cant get it worked.
<input type=text id='token' name="token"/>
<input type=button name=login value="login" onClick=changeQuery()/>
changeQuery(){
var input_query=document.getElementById('sq').value;
window.location="http://www.google.com/"+input_query+"myString";
}

There are many issues with your code...
HTML attribute should be in quotes (so change things like onclick=changeQuery() to onclick="changeQuery()")
Your function does not start with the keyword function
Your textbox control has an id of token... so in the example you have, there is no sq for the getElementById to find
And I'm not sure why you're adding "MyString" at the end of the URL, but that might be part of your intended code
The result should be something like this...
function changeQuery(){
var input_query = document.getElementById('token').value;
//window.location = "http://www.google.com/" + input_query + "myString";
console.log("http://www.google.com/" + input_query + "myString");
}
<input type="text" id="token" name="token"/>
<input type="button" name="login" value="login" onClick="changeQuery()"/>
(Please note, I've commented out the window.location and instead put a console.log so you can see what is produced without it actually navigating to another page)

function changeQuery() {
var input_query =
document.getElementById('token').value;
window.location = "https://www.google.com/search?
q=" + input_query;
}
Above is the correct code for what you want, but google doesn't allow some different origin to make search request.
Refused to display 'https://www.google.com/search?q=somequery' in a frame because it set 'X-Frame-Options' to 'sameorigin'.If you try to redirect some other origin it will work.

Related

How can make a program so as to get Search Results in another Window

I am udemy learner of javascript and In one the recent classes I learnt how to format url string the using javacscript.
Now I want to make a program in which user enters the string (say - harry potter) in form text input field and then on clicking button it redirects to second page and display that string search in BING search engine.
I tried to write some code but I failed. Can anybody help me ??
Following are the files I made
pastebin.com/syCzrqEe
pastebin.com/AgvCgCif
<form>
<input type="text" id="myinput">
<input type="submit">
</form>
<script>
document.forms[0].onsubmit = function() {
var query = document.getElementById('myinput').value;
window.open('http://www.bing.com/search?q=' + encodeURIComponent(query));
return false;
}
</script>

Using an input to search a local webpage in HTML

I'm stuck on this problem for now a couple of days and I have no idea what to do. I want to navigate directly to another page from my own website only by writing the page name(without the ".html" or ".php" in the input.
Example: you write "index" in the textbox and once you click on the submit button it sends you to "http://www.website.com/index.html". Instead of doing that, it sends me to "http://www.website.com/?2016=index&.=html"
I got it totally wrong because it sends the input names and some symbols around them.
This is my HTML code:
<form id="newsearch" method="get" action="http://www.website.com/">
<p>Enter your confirmation number:</p>
<input type="text" id="searchvalue" class="textbox1" name="2016" size="50" maxlength="120"><input type="submit" class="button1" value=">">
<input type="hidden" id="hiddenvalue1" name="." value="html">
</form>
Your current code simply submits a form, so it is quite correctly adding the entered value as part of the query string ?2016=index&.=html".
To navigate to the location, add a submit handler to the form that cancels the default form navigation and instead sets window.location to the relevant value, perhaps something like this:
document.getElementById("newsearch").addEventListener("submit", function(e) {
e.preventDefault();
var searchText = document.getElementById("searchvalue").value;
var extension = document.getElementById("hiddenvalue1").value;
window.location = this.action + searchText + "." + extension;
// or if you don't want to use the form's action attribute to specify
// the domain you could hardcode it in the function:
// window.location = "http://www.website.com/" + searchText + "." + extension;
});
(Update: the above code would need to be in a script element that is after the form element, and/or in a DOMContentLoaded or window.onload handler.)

How to pass form input and music from one page to another using JavaScript?

So I've been stuck on this for a while now. I have the first page which includes this form:
<form id="user" name="user" method="GET" action="the-tell-tale-heart.html">
Name: <input type="text" name="name">
<br/>
<input type="radio" name="soundtrack" id="st1" value="oldMansion">Soundtrack 1
<br/>
<input type="radio" name="soundtrack" id="st2" value="champion">Soundtrack 2
<br/>
<input type="submit" value="Submit">
</form>
I want the user to have entered the name and chosen a soundtrack. The submit button would redirect them to a second page (the-tell-tale-heart.html) where their name would appear at the top saying "Hello, " and the soundtrack they chose would play.
I've been told to use parse URL to get this info on the second page. I only want to use javascript, no php or perl. This is what I have so far:
<script>
var name="";
var url=document.URL;
function findName(){
var re=/(name)\=(.*)?&/;
name=url.match(re);
name=name.substring(5);
alert(name);
}
findName();
var oldMansion = new Audio('music/stories-of-the-old-mansion.mp3');
var champion = new Audio('music/champion.mp3');
// play one or the other depending on which the user chooses IF STATEMENTS :D
if {
oldMansion.play();
}
else {
champion.play();
}
</script>
I'm not sure what the conditions for the music would be.
EDIT:
So the findName() function actually gets this part of the URL:
?name=izzy&soundtrack=champion
and cuts it down to this on the second page:
izzy&,name,izzy
I would just like to get "izzy" and put that on the top of the page.
Try this:
// ... your code
if(url.indexOf('soundtrack=oldMansion') != -1) oldMansion.play();
else champion.play();
If you're using javascript, you really should just initiate the music on the page you're already on. There's no point in submitting a form to another page - that's the whole point of javascript - making a more user-friendly, interactive design without breaking up the experience with new page loads.
Also, look into jQuery.

Python Click Different Buttons

Is there a way or method to click one of two different buttons in Python? The relevant HTML code for the two buttons is:
<input type="text" id="target" name="target" size="80" value="https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u="style=\'display:none;\'>\n
<input type="button" id="training" name="training" style="width:200px;" value="Continue to Training" onclick="window.open(\'tr_redir.php\');" />
<input type="button" id="continue" name="continue" style="width:200px;" value="Continue to Forecasting Site" onclick="pm_go();" />
The button I need to click when I access manually the website is the second (last row) with id="continue" and onclick="pm_go();"
I tried with requests post and get methods without success.
import requests
s = requests.Session()
r = s.post(Log_URL, data={"target":'https://gj3s.inklingmarkets.com/memberships/2010/profile'})
The script pm_go provides the target webpage
function pm_go(){
var target_path = document.getElementById('target').value;
if( target_path == '' ){
alert("A target path is not yet defined for this Condition.");
} else {
document.location = "pm_redir.php?target=" + target_path;
}
Thanks to the suggestions and prodding by #Md-Mohsin I recorded the session with Chrome FN12 the Network tab, preserve the log. What I discovered was that after sign in authorization, I was supposed to enter a URL with a target.
The URL parameter I was using for the requests.Session().get was
https://gj3s.inklingmarkets.com/ + something else
instead the URL above is supposed to be passed as a target parameter in a different, longer URL
https://www.goodjudgmentproject.com/forecasting/pm_redir.php?target=https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u=
The recorded log of the showed all the addresses, in the POST and in the GET action to log in. I found the one I pasted above. I guess that's what the JavaScript was doing. So now my code to access the website in two steps is
user= 'my_e-mail_address#gmail.com'; pw = 'my_password'
Log_URL= 'https://www.goodjudgmentproject.com/forecasting/login.php'
Welcome_URL= 'https://www.goodjudgmentproject.com/forecasting/pm_redir.php?target=https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u='
s = requests.Session()
r = s.post(Log_URL, data={"email":user, "password":pw})
r = s.get(Welcome_URL)

Javascript Form Open URL in new tab

I have a piece of code that I have been getting help on and I have come across something that I find inconvenient. When I click the "Go" button it browses away from the current tab. I want to have the resulting URL from the form to open in a new tab. in addition I cannot hit the enter key because it will just load the whole form up in a new window. How do I correct the "enter" key usage problem and get my form to open the URL in a new tab. The forms function is to open a new URL that contains information I am searching for. Here is my code:
<script type="text/javascript">
function setSearchTermSN(n){
var SN_VALUE = encodeURIComponent(document.getElementById("sn").value);
location.href = "http://URL to site.com/perl/search?searchtype=sn&type=2&uid=" + SN_VALUE + "&visualtype=html%2Fen&tabset=person";
}
</script>
<form target="_blank">
Last Name: <input id="sn" type="text" value="" />
<input type="button" value="Go" onclick="setSearchTermSN()" />
</form>
the idea is to enter a last name such as Jones into the input box. Click go and the form would substitute " + SN_VALUE + " with Jones and the load the URL like this:
http://URL to site.com/perl/search?searchtype=sn&type=2&uid=Jones&visualtype=html%2Fen&tabset=person
the form currently does the substitution but it browses away from the search box which defeats the purpose of having it. I have tried the <form target="_blank"> but it still opens the URL in the same page.
credit for the above code goes to https://stackoverflow.com/users/904428/david
window.location only deals with the current document. You need to use window.open
Missed the other part about the enter key. You need a onkeyup event listener and check the event keycode for the return key and then run the same function as the click.
function setSearchTermSN(n){
var SN_VALUE = encodeURIComponent(document.getElementById("sn").value);
var newwindow = window.open("http://URL to site.com/perl/search?searchtype=sn&type=2&uid=" + SN_VALUE + "&visualtype=html%2Fen&tabset=person",'name');
return false;
}

Categories

Resources