Reply
Disable Form Button
Old 04-09-2008, 06:06 PM Disable Form Button
Novice Talker

Posts: 5
Name: Tom
I have been having an issue getting a form's submit button to disable and still process the form. What I did works in Firefox, but not in Internet Exlporer.

Basically, the site is for a user to enter a password and they are presented with a list of dynamically generated files they can download. When a user clicks a button, we want the button (I'm using image as the type) to swap to a "greyed out" style and then disable the button so that they cannot keep downloading the file over and over.

Here is the javascript I am using to disable/swap the button:

<script language="JavaScript" type="text/javascript">
function formDisable(id)
{

document.getElementById(id).disabled=true;
document.getElementById(id).src="../images/getitnowbuttonoff.gif";

}
</script>

And here is the form:

echo '<FORM ACTION="download.php" METHOD="post">';
echo '<INPUT TYPE="hidden" VALUE="' . $code . '" NAME="code">';
echo '<INPUT TYPE="hidden" VALUE="' . $table . '" NAME="table">';
echo '<INPUT TYPE="hidden" VALUE="' . $file . '" NAME="filename">';
echo '<INPUT TYPE="hidden" VALUE="' . $available_count . '" NAME="available_count">';
echo '<INPUT TYPE="hidden" VALUE="' . $counter . '" NAME="file_num">'; // File number
echo '<INPUT TYPE="hidden" VALUE="' . $number . '" NAME="structure">'; // download directory
echo '<INPUT id="' . $id . '" TYPE="image" src="../images/getitnowbutton.gif" width="135" height="29" onmouseup="formDisable(\'' . $id . '\')">';
echo '</FORM>';

We had to pass a variable to the JavaScript because there can be more than one form depending on how many files our clients submit. I had it working in both browsers before doing this, however if I clicked "button #5", only "button #1" would disable/swap.

Hopefully I made sense and someone could help me out with this. I would be extremely grateful as this has been driving me nuts for two days
alwaysintense is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-09-2008, 06:48 PM Re: Disable Form Button
tripy's Avatar
Fetchez la vache!

Posts: 1,822
Name: Thierry
Location: In the void
looks like your form is bit of a php loop.
Can you post the result out of your browser please (into a [ html ] [ /html ] block - without the spaces) ?
Looking at the php source won't help us, as the javascript is working on the result.

Thanks
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-09-2008, 07:02 PM Re: Disable Form Button
Novice Talker

Posts: 5
Name: Tom
Here's an example with two forms:
HTML Code:
<FORM ACTION="download.php" METHOD="post">
<INPUT TYPE="hidden" VALUE="01-e9661e9" NAME="code">
<INPUT TYPE="hidden" VALUE="tom01" NAME="table">
<INPUT TYPE="hidden" VALUE="Anthrax_-_Madhouse.mp3" NAME="filename">
<INPUT TYPE="hidden" VALUE="2" NAME="available_count">
<INPUT TYPE="hidden" VALUE="1" NAME="file_num">
<INPUT TYPE="hidden" VALUE="01" NAME="structure">
<INPUT id="getitnow1" TYPE="image" src="../images/getitnowbutton.gif" width="135" height="29" onclick="formDisable('getitnow1')">
</FORM>

<FORM ACTION="download.php" METHOD="post">
<INPUT TYPE="hidden" VALUE="01-e9661e9" NAME="code">
<INPUT TYPE="hidden" VALUE="tom01" NAME="table">
<INPUT TYPE="hidden" VALUE="Anthrax_-_Medusa.mp3" NAME="filename">
<INPUT TYPE="hidden" VALUE="4" NAME="available_count">
<INPUT TYPE="hidden" VALUE="2" NAME="file_num">
<INPUT TYPE="hidden" VALUE="01" NAME="structure">
<INPUT id="getitnow2" TYPE="image" src="../images/getitnowbutton.gif" width="135" height="29" onclick="formDisable('getitnow2')">
</FORM>

Last edited by alwaysintense : 04-09-2008 at 07:03 PM.
alwaysintense is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 04:24 AM Re: Disable Form Button
tripy's Avatar
Fetchez la vache!

Posts: 1,822
Name: Thierry
Location: In the void
Hmmm, can we see the final page ?
I don't see any reason it would always take the first image in your code.
Everything looks correct.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 04:28 AM Re: Disable Form Button
chrishirst's Avatar
Super Moderator

Posts: 11,507
Location: Blackpool. UK
Having two forms with the same name is always going to cause some problems with client side scripting.

And IE doesn't like referencing form elements using getElementById
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-10-2008, 04:56 AM Re: Disable Form Button
tripy's Avatar
Fetchez la vache!

Posts: 1,822
Name: Thierry
Location: In the void
I did not knew about the getElementById() problem of IE.
I remember having already used it with no problems, but in IE7.
Never bothered installing a VM with IE6 to test it.

But...
Those forms up there have no names, so they should not conflict with each others.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 12:08 PM Re: Disable Form Button
Novice Talker

Posts: 5
Name: Tom
Here's the whole thing:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Get It Now!</title>
<link href="styles.php" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
	function formDisable(id)
	{	
	
		document.getElementById(id).disabled=true;
		document.getElementById(id).src="../images/getitnowbuttonoff.gif";
		
	}
</script>

</head>

<BODY><DIV ID="main"><DIV id="header"><IMG SRC="profile/logo.jpg" WIDTH="327" HEIGHT="121" /><BR><BR></DIV><DIV ID="main-content"><div align="center"><div id="download"><div id="artistinfo"><h1>Members</h1>Tom, Josh<p><p><h1>Artist Bio:</h1>In today's market of downloading various media, we created the download card for our clients to distribute their music, film, media and technology by creating their own digital download cards for promotion or for sell. Card holders are not required to sign up for an account on our website to redeem their download, nor are they added to any email list. In fact they connect directly to our client's specific web destination.

When you choose to use our download cards for your promotion or sell of your digital media in the physical world, you can count on our knowledge and expertise to make the experience easy and stress free. </p><BR><p><h1>Contact Artist at:</h1><A HREF="mailto:alwaysintense@gmail.com">alwaysintense@gmail.com</A><BR><p><h1>Home Page:</h1><A HREF="http://www.alwaysintense.com" TARGET="_blank">http://www.alwaysintense.com</A><BR><BR><div class="trackcontainer"><div class="tracktitle">Anthrax - Madhouse</div><div class="getbutton"><FORM ACTION="download.php" METHOD="post"><INPUT TYPE="hidden" VALUE="01-72f3803" NAME="code"><INPUT TYPE="hidden" VALUE="tom01" NAME="table"><INPUT TYPE="hidden" VALUE="Anthrax_-_Madhouse.mp3" NAME="filename"><INPUT TYPE="hidden" VALUE="2" NAME="available_count"><INPUT TYPE="hidden" VALUE="1" NAME="file_num"><INPUT TYPE="hidden" VALUE="01" NAME="structure"><INPUT id="getitnow1" TYPE="image" src="../images/getitnowbutton.gif" width="135" height="29" onclick="formDisable('getitnow1')"></FORM></div></div><p><div class="trackcontainer"><div class="tracktitle">Anthrax - Medusa</div><div class="getbutton"><FORM ACTION="download.php" METHOD="post"><INPUT TYPE="hidden" VALUE="01-72f3803" NAME="code"><INPUT TYPE="hidden" VALUE="tom01" NAME="table"><INPUT TYPE="hidden" VALUE="Anthrax_-_Medusa.mp3" NAME="filename"><INPUT TYPE="hidden" VALUE="4" NAME="available_count"><INPUT TYPE="hidden" VALUE="2" NAME="file_num"><INPUT TYPE="hidden" VALUE="01" NAME="structure"><INPUT id="getitnow2" TYPE="image" src="../images/getitnowbutton.gif" width="135" height="29" onclick="formDisable('getitnow2')"></FORM></div></div><p></div><div id="artistimage"><IMG SRC="profile/album.jpg" WIDTH="272" HEIGHT="272" /><BR><BR><BR><TABLE cellspacing="5"><TR><TD><IMG SRC="gallery/MTII2418.jpg" WIDTH="80" HEIGHT="80"></TD><TD><IMG SRC="gallery/Uss_iowa_bb-61_pr.jpg" WIDTH="80" HEIGHT="80"></TD></TR><TR><TD><IMG SRC="gallery/MTII2395.jpg" WIDTH="80" HEIGHT="80"></TD><TD><IMG SRC="gallery/MTII2405.jpg" WIDTH="80" HEIGHT="80"></TD></TR></TABLE></div></div></div></div>
<div id="footer">
		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="271" height="76" id="Untitled-1" align="top">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="../images/admin/footerlogo.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="../images/admin/footerlogo.swf" quality="high" bgcolor="#ffffff" width="271" height="76" name="Untitled-1" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object><img src="../images/footerspacer.gif" width="124" height="1" /><a href="http://www.miduplication.com" target="_blank"><img src="../images/footermid.jpg" alt="Presented by Mirror Image Media &amp; Duplication" width="216" height="74" border="0" /></a>
</div>
</body>
</html>
alwaysintense is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 01:54 PM Re: Disable Form Button
tripy's Avatar
Fetchez la vache!

Posts: 1,822
Name: Thierry
Location: In the void
Ok, I just played with it 1 minute, but I think I have spotted your problem.

The problem I see is that when you click the "submit" image, the form actually submit itself, so it resets itself too.

I added an onsubmit="javascript:return false" into the forms, to prevent the action to take place, and I see the correct button getting disabled.
For info, I'm on firefox 3 beta 5 on linux.

So, your problem might be more related to the way your page works than simply javascript.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 03:36 PM Re: Disable Form Button
Novice Talker

Posts: 5
Name: Tom
OK, I just added onsubmit="javascript: return true;" to the form, and it fires the form and disables the button in Firefox but still not in IE. In IE, it's only disabling the button(s). return false wouldn't allow the form to fire.
alwaysintense is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 07:08 PM Re: Disable Form Button
tripy's Avatar
Fetchez la vache!

Posts: 1,822
Name: Thierry
Location: In the void
Well, I just logged on a winXp computer, and the form react ok with IE7.
It's the good submit that is disabled.
Do you had this problem on IE7 or IE6 ?
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-13-2008, 04:43 PM Re: Disable Form Button
Novice Talker

Posts: 5
Name: Tom
It's IE6 and 7 that are giving me headaches. I'm running Windows XP Pro, and the other guy I'm working with is running Macintosh and Linux machines. He is also experiencing the same problem with IE.
alwaysintense is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Disable Form Button
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.17705 seconds with 13 queries