Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
URGENT: Please convert this Python Script to Javascript?
I'm trying to make a simple database run on a html page i have coded it in Python 2, but it's server side not client side O.O. Therefore you would be helping me alot by converting this to javascript. I need a box with a button to be displayed on the page. You would input a users name press submit and it would show Name, Rank, Joined Date.
Script:
user1 = "Xx.:Abbas:.xX"
rank1 = "Founding Father"
joined1 = "N/A"
user2 = "jacksimpson"
rank2 = "Joint Founder"
joined2 = "Apr 19, 2014"
user3 = "::.Charlieboy.:"
rank3 = "1st Founder"
joined3 = "Apr 23, 2014"
user4 = "EpicLewis."
rank4 = "Chief Of Staff"
joined4 = "Apr 20, 2014"
var = raw_input('Please enter the first name of your target: ')
if var == "Xx.:Abbas:.xX":
print "Name: %s" % user1
print "Rank: %s" % rank1
print "Date Joined: %s" % joined1
if var == "jacksimpson":
print "Name: %s" % user2
print "Rank: %s" % rank2
print "Date Joined: %s" % joined2
if var == "::.Charlieboy.:":
print "Name: %s" % user3
print "Rank: %s" % rank3
print "Date Joined: %s" % joined3
if var == "EpicLewis.":
print "Name: %s" % user4
print "Rank: %s" % rank4
print "Date Joined: %s" % joined4
2 Answers
- DominicLv 77 years agoFavorite Answer
Here's and example.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<input type="text" id="name">
<input type="button" id="btn" value="Get Record">
<p id="output"></p>
<script>
var users = [];
users.push({
name: "Xx.:Abbas:.xX",
rank: "Founding Father",
joinedDate: "N/A"
});
users.push({
name: "jacksimpson",
rank: "Joint Founder",
joinedDate: "Apr 19, 2014"
});
users.push({
name: "::.Charlieboy.:",
rank: "1st Founder",
joinedDate: "Apr 23, 2014"
});
users.push({
name: "EpicLewis.",
rank: "Chief Of Staff",
joinedDate: "Apr 20, 2014"
});
function getRecordByName(name) {
var i;
for (i = 0; i < users.length; i++) {
if (users[i].name === name) {
return users[i];
}
}
return false;
}
function main() {
var name = document.getElementById("name").value;
var record = getRecordByName(name);
var output = "";
if (record) {
output += "Name: " + record.name + "<br>";
output += "Rank: " + record.rank + "<br>";
output += "Joined: " + record.joinedDate + "<br>";
}
document.getElementById( "output" ).innerHTML = output;
}
document.getElementById( "btn" ).onclick = main;
</script>
</body>
</html>
- 7 years ago
Oh boy. This is wrong on so many different levels.
Mixing data with code = bad
Case statements for every possible case = bad
Accidentally coding in wrong language = bad
Go learn JavaScript from a proper reputable source, please. Also don't ask Yahoo to do your homework. <3