Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Interesting error with Prototype...
Old 10-27-2008, 10:15 AM Interesting error with Prototype...
Average Talker

Posts: 24
Location: Boston, MA
Trades: 0
Hi all.

I'm using prototype.js to validate fields in a form prior to submission.

Code:
 <script type="text/javascript">
    
    function validate() {
   if ($F('required') == '') {
      new Insertion.After('bclabel', ' <b>(Required!)</b>');
      return false;
   }
   return true;
}

</script>
I then add an id="required" to the input field, and then a label afterwards where the desired error msg appears.

The thing is, this WORKS but only for one field. I want to validate that all fields have at least 1 character in them - how do I go about doing this?
__________________

Please login or register to view this content. Registration is FREE
spunko2010 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2008, 04:24 AM Re: Interesting error with Prototype...
Average Talker

Posts: 25
Trades: 0
try this:
Quote:
<input id="required0"><span id="bclabel0"></span>
<input id="required1"><span id="bclabel1"></span>
<input id="required2"><span id="bclabel2"></span>
<script type="text/javascript">

function validate() {
for(var i=0;i<3;i++)
if ($F('required'+i) == '') {
new Insertion.After('bclabel'+i, ' <b>(Required!)</b>');
return false;
}
return true;
}

</script>

or:
Quote:
<input id="required0"><span id="required0_lbl"></span>
<input id="required1"><span id="required1_lbl"></span>
<input id="required2"><span id="required2_lbl"></span>
<script>
function validate() {
var ins=document.getElementsByTagName("input");
for(var i=0;i<ins.length;i++){
if(ins[0].value==''){
new Insertion.After(ins[0].id+"_lbl", ' <b>(Required!)</b>');
return false;
}
}
return true;
}
</scipt>
__________________
Impossible means I'm possible.

Last edited by softhink; 11-06-2008 at 04:29 AM..
softhink is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Interesting error with Prototype...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.10203 seconds with 12 queries