Jump to content

If + prompt


es131245

Recommended Posts

The idea is too set something like filter for friends by name for a privet site <script language="javascript">var name =prompt("Welcome. Your nickname?","Nick here...") if name.value == "URL for a list of friends who are allowed to access" {document.write(name+"Welcome");} else{document.write(name+"You do not have a permission to access");</script>any ideas are welcome + i understand than its still not safe i like the idea it selfPS im new in JS

Link to comment
Share on other sites

Anything client-side is inherently insecure as users can either disable JavaScript or just modify the code. Ever looked at PHP? Also, you'll need to use AJAX to GET that list of friends client-side.

<?php	if (!isset($_COOKIE['name'])) {		if (!isset($_POST['name'])) {			echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">Form with field named 'name'</form>";		} else {			include("file-with-array-of-names-in-$names.php");			if (in_array($_POST['name'], $names)) setcookie("name", $_POST['name'], time() + 60 * 60 * 24);			else {				header("location:{$_SERVER['PHP_SELF']}");				exit();			}		}	}	if (isset($_COOKIE['name'])) {		echo "<h1>Welcome back, {$_COOKIE['name']}.</h1>";		//secure content here	}?>

Link to comment
Share on other sites

i understand but the main question is still how can i use prompt() command and use prompt.value with if???? for example prompt question "2+2=???" if prompt.value =="4" document.write("your clever!") else document.write("wrong answer")

Link to comment
Share on other sites

i finaly got it =)))))))) sorry for question but ive used 2 if instead if...else.... <script type="text/javascript">var namename=prompt("Nick?","zero");if (name=="zero") {alert("I love you!");}if (name!="zero"){alert("ok=)))");}</script>

Link to comment
Share on other sites

You can use if...else..., there shouldn't be anything wrong with that.

<script type="text/javascript">	var name = prompt("Nick?","zero");	if (name == "zero") {		alert("I love you");	} else {		alert("ok");	}</script>

Link to comment
Share on other sites

thx ive got it =))))0 I more question... WHATS WRONG????<html><head><script type="text/javascript">function ask(){var n=prompt("number?","0");};switch(n){case 1:document.write("I");break;case 2:document.write("II");break;default:alert("other"};break;}</script></head><body><input type="button" onclick="ask()" value="#123" /></body></html>

Link to comment
Share on other sites

By using document.write() inside a function you're going to make the page get cleared before being written on.I never recommend document.write() to output information.You can put the information in a <div>, something like this:HTML:

<div id="output"></div>

Javascript:

document.getElementById("output").innerHTML = "Text";

Link to comment
Share on other sites

What about... registry in JS for example for prompt...for example im using prompt and if....var name = prompt("Nick?",""); if (name == "zero") but person can write nick in many ways like Zero, ZeRo, ZerO, ZERO... and much more but this doent look nice...var name = prompt("Nick?",""); if (name == "zero","Zero","ZeRo","ZerO","ZERO") is ther such a command in JS like in php<?php define ( "USER" , "Root" , true )

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...