NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Javascript needed. (Np$+rep+tr)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 06-28-2005, 08:57 AM THREAD STARTER               #1 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Javascript needed. (Np$+rep+tr)


Hello,

I'm not a JS fan, but I have to use JS somewhere on my site.. well here's what I need.

I need an easy javascript that will check my form to find any empty fields that user has left blank, and if any occur, it gives him an alert to fill in this or that. "form validation".

One thing I'm facing here, this code must work on all browsers. So this is the only requirement.

I'll pay 100np, and I'll also add to your TR/Rep. If you could help me with this code.
????: NamePros.com http://www.namepros.com/programming/102471-javascript-needed-np-rep-tr.html

I do not care whether you're the writer of the code or not. I just need it to work on all browsers. And please check that it does, because it's very important to my site.

Thank you

Porte is offline  
Old 06-28-2005, 09:21 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Brought to you by www.javascriptkit.net I tried it in Both IE and FF. And it worked.

Code:
//Step 1:Insert the below into the <head> section of your page:
<script>

/*
Check required form elements script-
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!
*/

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("One or more of the required elements are not completed. Please complete them, then submit again!")
return false
}
else
return true
}
</script>

//Step 2: Add the following inside the <form> tag of the form you wish to validate:

<form onSubmit="return checkrequired(this)">
--
--
</form>

//Specifying required elements: Now, to mark an element inside the form as "required", //simply prefix the element's name with the keyword "required". Uh? For example, using //the above example, the source code looks something like this:

<form onSubmit="return checkrequired(this)">

<input type="text" name="requiredname">
<input type="text" name="requiredemail">
<select name="requiredhobby">
<option>....</option>
</select>
<textarea name="comments"></textarea>

</form>

//Notice how the names of all of the required elements have one thing in common- //their names have the prefix "required". This indicates to the script that those are //elements that have to have input in them. For either text or textarea elements, this //means they have to contain some text; for selection list, this means at least one //selection has to be selected.

//Note: Due to the "optional" nature of check and radio boxes, this script cannot be //used to mark those elements as required (giving check or radio boxes a "required" //prefix will do nothing).
Eric is offline  
Old 06-28-2005, 09:40 AM THREAD STARTER               #3 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Hello, thanks for this..but there's something I'm doing wrong?

I put the code as :

Quote:
<html>
<head>
<script>

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea") &&tempobj.value=='')||(tempobj.type.toString().cha rA t(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("One or more of the required elements are not completed. Please complete them, then submit again!")
return false
}
else
return true
}
</script>

</head>
<body>

<form onSubmit="return checkrequired(this)">

<input type="text" name="requiredname">
<input type="text" name="requiredemail">
<select name="requiredhobby">
<option>....</option>
</select>
<textarea name="comments"></textarea>
<input type="submit" value="submit">
</form>
</body>
</html>
but then I receive this error:
????: NamePros.com http://www.namepros.com/showthread.php?t=102471

Quote:
Line: 11
Char: 108
Error: Expected ')'
Code: 0
URL: http://localhost/test.php
Porte is offline  
Old 06-28-2005, 11:35 AM   #4 (permalink)
NamePros Regular
Join Date: Jun 2005
Posts: 266
Simsi will become famous soon enoughSimsi will become famous soon enough
 



At a quick glance i'd suggest putting spapaces in this line:

if (((tempobj.type=="text"||tempobj.type=="textarea") &&tempobj.value=='')||(tempobj.type.toString().cha rA t(0)=="s"&&tempobj.selectedIndex==-1)){

To read:

if (((tempobj.type=="text" || tempobj.type=="textarea") && tempobj.value=='') || (tempobj.type.toString().charA t(0) == "s" && tempobj.selectedIndex==-1)) {
Simsi is offline  
Old 06-28-2005, 12:20 PM THREAD STARTER               #5 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Thanks, let me try it..

edit: It does not solve it.. still same error
Last edited by Designporte; 06-28-2005 at 12:25 PM.
Porte is offline  
Old 06-28-2005, 12:50 PM   #6 (permalink)
NamePros Regular
Join Date: Jun 2005
Posts: 266
Simsi will become famous soon enoughSimsi will become famous soon enough
 



Originally Posted by Designporte
Thanks, let me try it..

edit: It does not solve it.. still same error
Got a URL handy where i can see it DP?
Simsi is offline  
Old 06-28-2005, 01:15 PM   #7 (permalink)
Senior Member

Join Date: Apr 2005
Location: .ma.us
Posts: 1,880
DropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud ofDropLister has much to be proud of
 


Baby Health Save a Life Save The Children
try something like <script type='javascript'> I think you need to specify in that tag thats its javascript and not java or something...just looked it up try adding this <SCRIPT LANGUAGE="JavaScript"> instead of just script, it miught alter how the browser reads it, but i dont do js so....gl
__________________
DropLister is offline  
Old 06-28-2005, 01:19 PM   #8 (permalink)
NamePros Regular
Join Date: Feb 2004
Location: Student @ UConn
Posts: 411
gamex has a spectacular aura aboutgamex has a spectacular aura about
 



What about something like this? This seems to be a very simple script:

http://www.codetoad.com/javascript_f...ion_script.asp
__________________
Joe
gamex is offline  
Old 06-28-2005, 02:31 PM THREAD STARTER               #9 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Well, this script doesn't let me specify optional fields, it will just occur on all input fields.
Porte is offline  
Old 06-29-2005, 01:10 AM   #10 (permalink)
Account Closed
Join Date: May 2005
Location: NY, USA
Posts: 283
hasif has a spectacular aura abouthasif has a spectacular aura about
 




This is a code untill the require fields are filled submit button will be DIM after all the fields are filled the button will be active to submit.

Code:
<html>
<head>

  <!-- Required Changes to use Form Set Validation:

    1. var form_nm  = "myForm"   :: This declares the form name to validate.
    2. set="[optional,required]" :: a value of required makes it valid only if it matches the regexp.
    3. regexp="/^[regex here]$/" :: only needed for required elements.  Element is valid if it tests true to the regular expression.

    ==> To validate for a minal length:  /^.{#,}$/ :: where # represents the minimum length

  -->

  <style type="text/css">

    .fld {
      width:285px;
      text-align:center;
    }

    div#errors {
      color:red;
      font-weight:bold;
    }

  </style>

  <script type="text/javascript">


    /***************************************************
    * Original:    Hasif Ahmed
    * WebSite:     http://masterzone.net.tf
    * Email:       hasif5@gmail.com

    * Name:        From Set Validator
    * Description: Validates a given form by detecting
                   > its set and testing against its
                   > regular expression. All browsers pass.
    ***************************************************/

    var required = new Array();
    var form_nm  = "myForm";

    window.onload = function() {
      var elems = document.forms[form_nm].elements;
      for(var i=0,a;a=elems[i];i++) {
        if(a.getAttribute('set') == "required") {
          required[required.length] = i;
          a.onkeyup = function() {
            return isOk(this.form);
          }
        }
      }
      return isOk(document.forms[form_nm]);
    }

    function isOk(frm) {
      var error = new Array();
      for(var i=0,a;i<required.length;i++) {
        a=required[i];
        if(!eval(frm.elements[a].getAttribute('regexp')).test(frm.elements[a].value)) {
          error[error.length] = "Field "+ frm.elements[a].getAttribute('id') +" are not correctly filled in.";
        }
      }
  
      frm.elements[frm.elements.length-1].disabled = error.length;
      document.getElementById('errors').innerHTML = "Good to Go!";

      if(error.length) {
        document.getElementById('errors').innerHTML = error.join('<BR>');
      }
    }

  </script>
</head>

<body>
  <form name="myForm" action="someScript.pl" method="post">
    <fieldset class="fld"><legend>Fields: </legend>
      <!-- Validates with at least 1 digit, only digits -->
      Numbers: <input type="text" id="numbers" set="required" name="txt1" regexp="/^\d+$/"><BR>
      <!-- Optional -->
      Text2:   <input type="text" id="txt2"    set="optional" name="txt2"><BR>
      <!-- Optional -->
      Text3:   <input type="text" id="txt3"    set="optional" name="txt3"><BR>
      <!-- Validates with 5 letters, or more, no non-letters -->
      Letters: <input type="text" id="letters" set="required" name="txt4" regexp="/^[A-Za-z]{5,}$/"><BR>
      <button type="submit" name="sbmt" id="sbmt" disabled="true">Submit!</button>
    </fieldset>
  </form>

  <fieldset class="fld" style="height:100px;"><legend>Errors</legend>
    <div id="errors">
      Any errors will be posted here.
    </div>
  </fieldset>
</body>
</html>
Good luck, if its work then tell me, I have tried in the following browsers :-
????: NamePros.com http://www.namepros.com/showthread.php?t=102471
"FireFox" , "DeepAprk Alpha" , "Opera" , "Internet Explorer" , "MSN Explorer" , "Avant Browser" & "Netscape".
^It works fine in this browsers^
Last edited by hasif; 06-29-2005 at 01:16 AM.
hasif is offline  
Old 06-29-2005, 01:22 AM   #11 (permalink)
Senior Member
 
dotcommakers's Avatar
Join Date: Oct 2003
Location: world wide web
Posts: 2,055
dotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to behold
 




if u give me just a form.. i will put there java script so it will work for sure 100%
dotcommakers is offline  
Old 06-29-2005, 03:47 AM THREAD STARTER               #12 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Thanks guys, I'm not looking anymore..

Oh, well i have found it fair to share resources between both of you, thanks for the contributions.. and I think i found what i need.
Porte is offline  
Old 06-29-2005, 06:55 AM   #13 (permalink)
Account Closed
Join Date: May 2005
Location: NY, USA
Posts: 283
hasif has a spectacular aura abouthasif has a spectacular aura about
 



no problem, i good luck.
hasif is offline  
Old 06-29-2005, 03:55 PM   #14 (permalink)
NamePros Member
Join Date: Oct 2003
Posts: 126
i386 is an unknown quantity at this point
 



I think you could verify it on the script side with empty() in PHP.
i386 is offline  
Old 06-30-2005, 03:59 AM THREAD STARTER               #15 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Yes, I could, but I want the whole verification to go before submitting the page.
Porte is offline  
Old 06-30-2005, 04:27 AM   #16 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



point is though, if the user of your site dosen't have javascript enabled, or a browser which can't run javascript, you are stuck.
PoorDoggie is offline  
Old 06-30-2005, 04:57 AM THREAD STARTER               #17 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Yes Tom, heh..but I have considered that all users have JS
Porte is offline  
Old 06-30-2005, 05:03 AM   #18 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Originally Posted by Designporte
Yes Tom, heh..but I have considered that all users have JS
well then, your sorted. I was just pointing out that some people won't have js support. Sorry
PoorDoggie is offline  
Closed Thread

« md5 table | MYsql »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6 PROGRAMMER NEEDED will pay in NP$..or $ easy work jane118 For Sale / Advertising Board 1 12-07-2004 06:37 PM
Game - Minimum 100 NP$ in prizes - FREE TO PLAY ppx Contests Forum 25 12-06-2004 05:27 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:11 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger