Forum Moderators: open

Message Too Old, No Replies

Help with combing java actions

java two commands combined

         

mikefreemen

8:04 am on Jan 13, 2009 (gmt 0)

10+ Year Member



combining *

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');" />&nbsp;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>

janharders

8:12 am on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



shouldn't

<input type="checkbox" name="guest" onClick="showhide(this,'img1'); doGuest(...)" />

work?

if not, why not?

mikefreemen

8:20 am on Jan 13, 2009 (gmt 0)

10+ Year Member



a lil more help

this site is the best, fastest reply ever and IT WORKED! I usually dont donate money to sites but I will for this site. you guys rule!

Any idea why style=”display: none;” isnt hiding the div? and any idea how to make it back empty when they uncheck it?

janharders

8:34 am on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



glad to be of help!

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 = '';
}
}

isn't tested but should work I think. and remember to change the onclick-part of the checkbox accrodingly to pass "this" as the first argument to both functions.
btw:
if (uname.value != "" ¦¦ uname.value == "") {
will always be true, you're checking if uname.value is empty or wether it's not ... one of them has to be unless you're dealing with schroedinger's cat ;)

mikefreemen

4:26 pm on Jan 13, 2009 (gmt 0)

10+ Year Member



everything worked perfect, you are the man