Click to See Complete Forum and Search --> : Can someone help ne modify this code
Jupac
07-23-2003, 05:00 PM
Can some help with this
<html>
<head>
<script>
function MsgBox(e) {alert(e)}
function cuname(){
var check="0"
if (form1.text1.value != "username1"){check="1";}
if (check=="0") {MsgBox(form1.text1.value) is not taken is ok to use as username}
if (check=="1") {MsgBox(form1.text1.value) is taken try a diffrent Username}
}
</script>
</head>
<body>
<form onsubmit="cuname()" name="form1">
<input Name="text1" value="">
<input type="submit" name="submit" value="try">
</form>
</body>
</html>
Thanks
Exuro
07-23-2003, 05:41 PM
That post was extreamly unclear, but I think maybe you were after something like this:
<html>
<head>
<script type="text/javascript">
<!--
function cuname(userName){
var check = 0;
if (userName != "username1"){
check = 1;
}
if (check == 0) {
alert(userName + " is not taken, is ok to use as username");
}
else {
alert(userName + " is taken, try a diffrent Username");
}
}
//-->
</script>
</head>
<body>
<form onsubmit="cuname(this.text1.value)" name="form1">
<input Name="text1" value="">
<input type="submit" name="submit" value="try">
</form>
</body>
</html>
Have you by chance worked with VB/VBScript before? I got rid of the MsgBox function you were using because it was pretty much pointless. I also changed the cuname() function so that it accepts a parameter userName which is passed in onSubmit. If that wasn't what you were looking for then you should probably post something a more specific...
Jupac
07-23-2003, 08:48 PM
Thankx for help Exuro but it dose the oposite when i put in the username in it said that it is not taken and when i put in an untaken one it said taken
Jupac
07-23-2003, 08:57 PM
I played aroud with the script and it works!
<html>
<head>
<script type="text/javascript">
<!--
function cuname(userName){
var check = 0;
if (userName != "username1"){
check = 1;
}
if (check == 0) {
alert(userName + " is taken, try a diffrent Username");
}
else {
alert(userName + " is not taken, is ok to use as username");
}
}
//-->
</script>
</head>
<body>
<form onsubmit="cuname(this.text1.value)" name="form1">
<input Name="text1" value="">
<input type="submit" name="submit" value="try">
</form>
</body>
</html>
Thanks again anyway
Jupac
07-23-2003, 09:08 PM
hey man
It works only if i dont use more than 1 username i seperate then with , is that right?
Jupac
07-23-2003, 11:39 PM
yo
I dont no why i cant seperate the username with commas but if any1 could help i would aprecheate it. :')
Exuro
07-23-2003, 11:53 PM
I was wondering why you only wanted to have one username that was taken... Anyway, I edited the code:
<html>
<head>
<script type="text/javascript">
<!--
var names = new Array("Joe","Bob","[H]Chris Lewis[H]","spoofy923")
function cuname(userName){
var isOkay=1;
for (i=0;i<=names.length;i++) {
if (userName == names[i]) { isOkay=0; }
}
if (isOkay) {
alert(userName + " is not taken, is ok to use as username");
}
else {
alert(userName + " is taken, try a diffrent Username");
}
}
//-->
</script>
</head>
<body>
<form onsubmit="cuname(this.text1.value);return false;" name="form1">
<input Name="text1" value="">
<input type="submit" name="submit" value="try">
</form>
</body>
</html>
As you probably guessed, the User Names go inside the Array() separated by commas. Hope that helps!