JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 6th, 2007, 02:13 AM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 65 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 5 m 28 sec
Reputation Power: 4
Need Help Debugging Script/Error in Script - Need help with form validation and disable submit button

Hey there

I have a form in which I need the submit button disabled and for the form to be validated before submitting the data.. I've tried different ways but I can't seem to get it working properly.. The closest I've gotten it to work is the following code:

Code:
<script language='javascript'>

function ValidateForm(form)
{

	function IsNumeric(sText)
	{
	   var ValidChars = "0123456789";
	   var IsNumber=true;
	   var Char;
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
	   
	   }
	
	   if (!IsNumeric(form.price.value)) 
	   { 
		  alert('Please enter only numbers in the price fields') 
		  form.price.focus(); 
		  return false; 
		  } 
	 
	   if (!IsNumeric(form.price_g.value)) 
	   { 
		  alert('Please enter only numbers in the price fields')
		  form.price_g.focus(); 
		  return false; 
		  } 
	 
	return disableButton(document.form)
 
}

function disableButton(theButton) {
theButton.value="Uploading...";
theButton.disabled = true;
return true;
}

</script>


However, it's not submitting my data (am trying to upload files to my server)..

Here's my form tags:

Code:
<form action="uploader.php" method="post" enctype="multipart/form-data" name="form" id="form" onSubmit="javascript:return ValidateForm(this)">
.....
<input name="upload" type="submit" id="upload" value="Submit" />


Could someone please let me know what I'm doing wrong??

Thanks so much

Reply With Quote
  #2  
Old December 7th, 2007, 10:20 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 548 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 6 h 35 m 44 sec
Reputation Power: 4
not working

Only guessing, but I don't think you can pass the form object to the function that way. ie.
Code:
	return disableButton(document.form)
Maybe
Code:
function disableButton() {
var theButton = document.getElementById('upload');
theButton.value="Uploading...";
theButton.disabled = true;
return true;
}
__________________
WP plugins - Error Reporting, Clean Options
http://www.mittineague.com/dev/er.php
http://www.mittineague.com/dev/co.php

Reply With Quote
  #3  
Old December 8th, 2007, 06:35 PM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 65 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 5 m 28 sec
Reputation Power: 4
Quote:
Originally Posted by Mittineague
Only guessing, but I don't think you can pass the form object to the function that way. ie.
Code:
	return disableButton(document.form)
Maybe
Code:
function disableButton() {
var theButton = document.getElementById('upload');
theButton.value="Uploading...";
theButton.disabled = true;
return true;
}


That worked!! Thanks so much for your help!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need Help Debugging Script/Error in Script - Need help with form validation and disable submit button


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway