Forum Moderators: open
I am trying to have people click on the checkbox below and it will hide the password field. It already does this, but what I also need it to do is execute the function doGuest(uname) which basically put the words Guest in the username box. I have tried different things and I cant get it to work. Any ideas? also i have the div1 style set to no display yet its still showing up. Any help is appreciated.
thank you in advance.
<script language="JavaScript">
<!--
function formCheck(form) {
if (form.uname.value == "") {alert( "Please enter your username or sign in as guest. ");return false ;}
}
function doGuest(uname) {
if (uname.value != "" ¦¦ uname.value == "") {
uname.value = "Guest";
}
}
// -->
</script>
<script language="JavaScript">
function hide(id) {
document.getElementById(id).style.display = 'block';
}
function show(id) {
document.getElementById(id).style.display = 'none';
}
function showhide( el, img ) {
if ( el.checked ) { show(img); }
else { hide(img); }
}
</script>
<table width="50%" border="0" cellspacing="0" cellpadding="2" id="table2" align="center">
<form method="post" onSubmit="return formCheck(this)" action="/chat.php" name="login">
<input type="hidden" name="doLogin" value="1">
<input TYPE="hidden" VALUE="[*ChatName*]" NAME="room">
<input TYPE="hidden" VALUE="english" NAME="login_language">
<tr>
<td colspan="2" align="center">
<input name="uname" type="text" class="usernamefield" value="" />
<div ID="img1" style=”display: none;”>
<input type="password" name="password" class="passwordfield" value="" /></div>
<input type="checkbox" name="guest" onClick="showhide(this,'img1');" /> Login as Guest?<br>
Gender: <select name="login_gender" size="1">
<option value="0">Select<option value="1">Male<option value="2">Female<option value="3">Couple</select><br>
</td>
</tr>
<tr>
<td align="center">
<input name="submit" type="submit" class="loginbutton" value=""><br><br>
</form>
</table>
it seems you didn't use regular double quotes (") in the style-attribute.
as for clearing the username-field when they uncheck the box, maybe the easiest way to go is the way you're doing it with the showhide-function, e.g. passing the checkbox-element.
function doGuest(el, uname) {
if(el.checked) {
if (uname.value != "" ¦¦ uname.value == "") {
uname.value = "Guest";
}
}
else {
uname.value = '';
}
}