Javascript and Perl validation help please!

Soldato
Joined
16 Dec 2003
Posts
2,697
I'm using this function on my website which helps to validate text fields and drop down lists (sample code):

Code:
function Validator(theForm)
{
  var error = "";
		
  if (theForm.name.value == "")
  {
    error += "Name\n\n";
  }

  if (theForm.invoice_method.options[0].selected == true)
  {
    error += "Invoice method\n\n";
  }

  if (error != "")
  {
    alert(error);
    return (false);
  }
		
  else
  {
    return (true);
  }
}

I've tried looking around how to validate radio buttons, there's lots of different ways of doing it :confused:, are there any easy examples out there that anyone provide please? :o

I'm also having problems with my Perl code, is there anything wrong with my if statement? It doesn't seem to work properly as it's not printing anything if I type something in the address line 2 field :confused:

Code:
if (@address_line_2{'address_line_2'} eq "")
{
  print "\n";	
}
else
{
  print "              @address_line_2\n";
  print "              <br/>\n";
}

Please help! :)
 
What I'm trying to do in my Perl statement is that if the user hasn't entered a address line 2, it won't print anything. If the user has entered something it'll print it, I was using these lines for my perl script:

Code:
print "              @address_line_1\n";
print "              <br/>\n";
print "              @address_line_2\n";
print "              <br/>\n";
print "              @city\n";
print "              <br/>\n";
print "              @province\n";
print "              <br/>\n";
print "              @post_code\n";
print "              <br/>\n";
print "              @country\n";
print "              <br/>\n";

Let's say the user hasn't entered an address line 2 (it's not compulsory) it creates a blank line in the address. I'm using the if statement as shown in my first post to get rid of the blank line, it doesn't seem to work :confused:
 
I'm not familure with Perl but if you say that the 'else' clause never executes then I suspect the if statement is always true.

What does this:
Code:
@address_line_2{'address_line_2'} eq ""
do?

Rather than printing a new line in your if statement print some text, see if it is reproduced every time. If it is there is somthing wrong with your if statement.

Justin
 
The line detects if the textbox from the HTML form is empty, it won't print anything (no spaces or lines), if the user has typed something it'll print what has been typed in the textbox.
 
I've fixed the JavaScript problem now :o

I'm not sure why the Perl isn't working :confused:

I've got another problem with Perl where I'd like to match a specific color from an array using an if statement, here's the Perl code:

Code:
my @colors = param('color');
foreach my $color (@colors) {
   print "You picked $color.<br>\n";
}
I've tried using "if (@colors eq "Red")", I've also tried changing the if statement parameter to $colors and it doesn't work :confused:

Please help! :o
 
Back
Top Bottom