disabling/enabling input type = image

liunx

Guest
i have two image gifs - A and B that act as submit buttons<br />
<br />
in the beginning i want A to be enabled and B to be disabled.<br />
then after A is clicked, I want B to be enabled. <br />
also, is it possible to have a message pop up if the user clicks B while it is disabled? any help appreciated.<!--content-->here is what i have so far. i have the second button disabled in the beginning. but once i click the first button which is login...the second button doesn't get enabled. what am i doing wrong?<br />
<br />
<HTML><br />
<HEAD><br />
<br />
<SCRIPT LANGUAGE="JavaScript"><br />
function UploadComplete(form) {<br />
alert("button enabled");<br />
}<br />
<br />
function Login(form) {<br />
var username = form.username.value;<br />
var password = form.password.value;<br />
var server = form.server.value;<br />
<br />
if(document.getElementById("list").disabled == true)<br />
{<br />
document.getElementById("list").disabled = false;<br />
}<br />
<br />
<br />
var local = "file://";<br />
if (username && password && server) {<br />
window.open(local, '_blank', <br />
'toolbar=yes,location=yes,status=yes,' + <br />
'scrollbars=auto,copyhistory=no,menubar=no,width=' <br />
+ ((screen.AvailWidth/2)-12) + ',height=' + <br />
(screen.AvailHeight-150-screen.AvailHeight/2) +',left=0,top=' + ((screen.AvailHeight/2+30)) <br />
+ '),resizable=yes');<br />
window.open("ftp://" + username + ":" + <br />
password + "@" + server, '_blank', <br />
'toolbar=yes,location=yes,status=yes,' + <br />
'scrollbars=auto,copyhistory=no,menubar=no,width=' <br />
+ ((screen.AvailWidth/2)-12) + ',height=' <br />
+ (screen.AvailHeight-150-screen.AvailHeight/2) +',left=' + ((screen.AvailWidth/2)) <br />
+ '),top=' + ((screen.AvailHeight/2+30)) <br />
+ '),resizable=yes');<br />
}<br />
else {<br />
alert("Please enter a username, password, and server name");<br />
}<br />
}<br />
</script><br />
<br />
</HEAD><br />
<br />
<br />
<TITLE>Client</TITLE> <br />
<br />
<br />
<BODY><br />
<H1><img src=http://www.webdeveloper.com/forum/archive/index.php/"matrix_head.jpg" width="900" height="100"><img src="matrix_title.jpg" width="900" height="40"></H1><br />
<form name="StartupForm"><br />
<br />
<p> <img src=http://www.webdeveloper.com/forum/archive/index.php/"login.jpg" width="500" height="22"> </p><br />
<p><br />
<table width='87%' border='0' cellpadding='0' cellspacing='1'><br />
<tr> <br />
<td width="21%" align='right'><p align="right"><font color="#00085E"><strong>Username:</strong></font>&nbsp;</p></td><br />
<td colspan="3"> <input type='text' <br />
name='username' value='system' size='20' <br />
maxlength='20'> &nbsp;&nbsp;</td><br />
</tr><br />
<tr> <br />
<td align='right'><div align="right"><font color="#00085E"><strong>Password:</strong>&nbsp;</font></div></td><br />
<td colspan="3" class='darkcell'> <input type='password' <br />
name='password' value='blah' size='20' <br />
maxlength='20'> &nbsp;&nbsp;</td><br />
</tr><br />
<tr> <br />
<td align='right'><div align="right"><font color="#00085E">&nbsp;<strong>Server:&nbsp;</strong></font></div></td><br />
<td width="19%" class='darkcell'> <input type='text' <br />
name='server' value='ussv' size='20' <br />
maxlength='120'> &nbsp;&nbsp; </td><br />
<td width="14%" class='darkcell'><input name="login" type="image" style='color:#000000' onClick='Login(this.form)' value='Select Device File' <br />
src = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"login_button.jpg" align="middle"></td><br />
<td width="46%" class='darkcell'><input name="list" type="image" disabled onClick="UploadComplete(form)" value="Upload Complete/Start Data Conversion!" <br />
src = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"view_file_button.jpg" ></td><br />
<br />
</tr><br />
</table><br />
<br />
</form><br />
<br />
</HTML><!--content-->Once an element is disabled it has no properties when using events.<br />
This method sets a boolen to determin the condition of the buttons/process.<br />
JavaScript<br />
<br />
var LOGIN=false;<br />
function UploadComplete(f) {<br />
if(LOGIN) {<br />
alert("button enabled");<br />
}<br />
else {<br />
alert("Login first");<br />
}<br />
}<br />
function Login(f) {<br />
if(LOGIN) {<br />
UploadComplete(f);<br />
}<br />
else {<br />
if(username && password && server) {<br />
// process input<br />
LOGIN=true;<br />
}<br />
else {<br />
alert("Please enter a username, password, and server name");<br />
}<br />
}<br />
}<br />
<br />
HTML<br />
<br />
<input name="login" type="image" onclick="Login(this);" value="Select Device File" src=http://www.webdeveloper.com/forum/archive/index.php/"login_button.jpg" /><br />
<input name="list" type="image" onclick="UploadComplete(this);" value="Upload Complete/Start Data Conversion!" src=http://www.webdeveloper.com/forum/archive/index.php/"view_file_button.jpg" /><br />
<br />
<br />
BTY You tried to document.getElementById("list").disabled == true when there was only name and no id<!--content-->thanks for the help fang. but is there a way to disable the second button in the beginning. and the ENABLE it later after the first button has been clicked?<!--content-->Yes, but you will have to change your input to button. (semantically better)<br />
<br />
This goes in Login() and is processed if the login is successful.<br />
document.getElementById("list").removeAttribute("disabled");<br />
document.getElementById("listImg").setAttribute("alt", "enabled");<br />
<br />
The input change to button:<br />
<button type="button" disabled="disabled" name="list" id="list" onclick="UploadComplete(this);" value="Upload Complete/Start Data Conversion!" style="border:0;background:transparent;"><img id="listImg" alt="disabled" src=http://www.webdeveloper.com/forum/archive/index.php/"bullet_b.gif" /></button><br />
<br />
Now you have a tooltip "disabled" initially which is changed to "enabled" once login is successful.<br />
The style hides the button.<br />
<br />
Why the change to button: the DOM is still very patchy in all browsers, particularly with form elements.<!--content-->
 
Back
Top