printing the contents of list in java - javascript

Trying write javascript that prints "username=john01" and "password=password123" from the url below. Currently it prints nothing...
index.html?username=john01&password=password123&lt=_c1F9F2B16-96B3-9D7B-CC19-D22A43D4FCA1_kA54D6D0E-881B-2792-22D3-B857150B1EFC&_eventId=submit&submit=Sign+In
<html>
<body>
<p> This code is for educational purposes only, and is not to be used with malicious intent. </p>
<script>
string = window.location.search;
content = string.split("");
usernameStart = 1;
usernameEnd = content.indexOf("&",0);
username = content.substring(usernameStart,usernameEnd));
document.write("Your username is " + username);
</script>
</body>
</html>

var url = 'index.html?username=john01&password=password123&lt=_c1F9F2B16-96B3-9D7B-CC19-D22A43D4FCA1_kA54D6D0E';
var username = url.match(/username=([^&]*)/)[1];
var password = url.match(/password=([^&]*)/)[1];
document.getElementById('userinfo').innerHTML = 'Your username is ' + username + '<br/>And your password is ' + password;
You can try it directly on my JSFiddle
If you replace 'url' with 'window.location' and remove the first line, it should work from the url.

Related

JavaScript searching for a user based on their username?

I've created a function that uses getJSON to retrieve a data set found on an API website of registered Github Users
<!DOCTYPE html>
<!---->
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function(){
var user = $('#search').val();
$.getJSON("https://api.github.com/users/" + user)
.done(function(data) {
var br = "<br>";
var p = $("<p id='users'></p>");
var name = "Username: "+ user.login + br;
var pic = "Avatar Picture:" + br + "<img src='"+user.avatar_url+"'/>" +br;
var homeURl = "Homepage URL: "+"<a href='"+user.html_url+"'>"+user.html_url+"</a>" +br;
var location = "Location: "+"Null" +br;
var admin = "Admin: "+user.site_admin;
p.append("<p>"+ name + pic + homeURl + location + admin +"</p>");
$("#results").empty().append(p);
})
.fail(function(jqXHR) {
console.log("Error: " + jqXHR.status);
})
.always(function() {
console.log("Random Users Request finished");
});
});
</script>
</head>
<body>
<input id="search" type = "text">
<button>Search</button>
<div id="results"></div>
</body>
</html>
As you can tell I have began to modify it so that instead of displaying all users it only displayers the user that has been searched
var user = $('#search').val();
$.getJSON("https://api.github.com/users/" + user)
This snippet of code grabes the username entered in the text area and passes it to the getJSON method in the Url. An example URL is "https://api.github.com/users/mojombo", thus if the user enters "mojombo" then their profile would appear
This function is accessed via a button
<input id="search" type = "text">
<button>Search</button>
However when you search for the example user, in fact any user no data is displayed and a blank screen remains
You have not connected your function to the button.
As it stands, it runs before the user has typed anything into the search field (thus requesting "https://api.github.com/users/" because user at that time is an empty string) , and won't react at all to a button click.
Instead of just
$(function(){
/* code */
});
do
$(function(){
$('button').on('click', function(){
/* code that runs when button is clicked */
})
});

how to write user input in whatsapp sharing message

In my website I have a whatsapp sharing button, so i want to send my website link with a parameter,
For e.g.
abcd.com/?name=userinput
This is the code of whatsapp sharing button.
<script type="text/javascript">
var userinput=prompt("Please Enter Your Name");
</script>
<script><a href="whatsapp://send?text= Link abcd.html?name="><b>share on whatsapp</b></script>
You can do this:
JS:
<script>
//Ask the user for name and store it on name variable
var name = prompt("Please Enter Your Name");
//This will be called when the link is clicked
function sendWhatsapp(){
var url = "www.abcd.com/?name=" + name;
var sMsg = encodeURIComponent( "hi this is " + name + " and my link is " + url );
var whatsapp_url = "whatsapp://send?text=" + sMsg;
window.location.href = whatsapp_url;
}
</script>
HTML:
<a onclick="sendWhatsapp()">share on whatsapp</a>
FULL HTML CODE:
<html>
<head>
<script>
//Ask the user for name and store it on name variable
var name = prompt("Please Enter Your Name");
//This will be called when the link is clicked
function sendWhatsapp(){
var url = "www.abcd.com/?name=" + name;
var sMsg = encodeURIComponent( "hi this is " + name + " and my link is " + url );
var whatsapp_url = "whatsapp://send?text=" + sMsg;
window.location.href = whatsapp_url;
}
</script>
</head>
<body>
<a onclick="sendWhatsapp()">share on whatsapp</a>
</body>
</html>

Turn a javascript to JSON

I am working on a task where the customer enters their contact information, and then all the details will appear on an alert box, I am facing a problem with converting a javascript code to JSON
<script type="text/language">
var
function getinfo() {
try{ var firstName =
document.myForm.firstName.value;
var LastName =
document.myForm.LastName.value;
FullName= firstName + LastName;
var Gender =
document.myForm.Gender.value;
var mail =
document.myForm.mail.value;
var Telephone =
document.myForm.Telephone.value;
var MobilePhone =
document.myForm.MobilePhone.value;
alert("FullName : "+FullName +"<br/> Mail: " + mail + "<br/>Telephone:" + Telphone +"<br/>Mobile: " + MobilePhone);
}catch(err){alert('Exception :: '+err)}
}
</script>
Your script has some errors:
it's document.forms.myForm and so on.
you didn't define "FullName" as a variable.
you use "Telphone" in the alertbox instead of "Telephone"
I've corrected them here:
<script type="text/language">
document.forms.myForm.elements.sub.onclick= function()
{
try{ var firstName = document.forms.myForm.firstName.value;
var LastName = document.forms.myForm.lastName.value;
var FullName= firstName + LastName;
var Gender =document.forms.myForm.Gender.value;
var mail = document.forms.myForm.mail.value;
var Telephone = document.forms.myForm.Telephone.value;
var MobilePhone =document.forms.myForm.MobilePhone.value;
alert("FullName : "+FullName +"<br/> Mail: " + mail + "<br/>Telephone:" + Telephone +"<br/>Mobile: " + MobilePhone);
}catch(err){alert('Exception :: '+err)}
}
</script>
But your script hasn't got to do anything with converting something to JSON.
You might use JSON.stringify() to "JSONify" your variables.

Fixing Syntax Error, on my Script Editor

function sendEmails(e){
var UserName = e.values[3];
var UserEmail = e.values[5];
var date = e.values[0];
var pin = e.values[4];
var subject = "[LFR] Application Succeed!";
var bodymessage = "Hi" + UserName + "for sending in your job application."
<br>
<br> + "The following is your Purchase Log Pin"
<br> + pin;
var emailsent = "Email Sent";
var isEmailsent = e.values[6];
if (isEmailsent ! = emailsent);
MailApp.sendEmail(UserEmail, subject, bodymessage);
}
The error message always shows, "Illegally formed XML syntax. (line 18, file "Code"). Someone please help me to fix it!
change this
var bodymessage = "Hi" + UserName + "for sending in your job application."
<br>
<br> + "The following is your Purchase Log Pin"
<br> + pin;
to
var bodymessage = "Hi" + UserName + "for sending in your job application.<br> <br>The following is your Purchase Log Pin<br>" + pin;
bascially, your string is not formed correctly
Also,
remove ; after the if statement
if (isEmailsent ! = emailsent)
{
MailApp.sendEmail(UserEmail, subject, bodymessage);
}

Tracking values using JavaScript

on page A
test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));
Response.Redirect("EnterSession.aspx?session=" + e.CommandArgument.ToString());
on page B
_gaq.push(['pageTrackerTime._trackEvent', 'category', 'action', document.location.href, roundleaveSiteEnd]);
when a user clicks a button on page A , he will be directed to page B and there I used document.location.href to track the current URL. now I would like to track as well session_name from page A using JavaScript.
how can I do this
the original code was like this
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * FROM Tmyapp_Session;";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
test.Controls.Add(GetLabel(thisReader["session_id"].ToString(), thisReader["session_name"].ToString()));
string[] compare = secondResult.Split(';');
foreach (string word in compare)
{
if (word == thisReader["session_id"].ToString())
{
test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session"));
I had to change the last code to
test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));
session_id to session_name
because i want to url to have the value of the session_name
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
// include getCookie and setCookie functions here
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var username = getCookie("username");
if (username != null) { // registered user
document.writeln("Welcome back " +
username + ".");
var visits = getCookie("visits");
document.writeln(" You have been here " +
visits + " time(s) before.");
setCookie("visits",parseInt(visits)+1);
}
else { // new user
var username = prompt("What is your name ?","");
if (username != null) {
setCookie("username",username);
setCookie("visits",1);
document.writeln("Thank you. Please reload this page.");
}
}
</SCRIPT>
</BODY>
</HTML>
Hope this will work !!!
Looks like you just need to get the session_name from the querystring. Check out this post here, it has a couple of nice solutions for doing that.
I see two ways of accomplishing what you want, you could add another querystring
/url.aspx?session_name=[session_name]&session_id=[session_id]
or in a session variable
session["session_id"] = session_id;

Categories

Resources