42 users online (0 members and 42 guests)  


  Results 1 to 2 of 2

Related

  1. urgent xml / xsl help    Forum: HTML Forum
    Replies: 0
  2. Need urgent help.    Forum: HTML Forum
    Replies: 0
  1. #1
    djmaddy's Avatar
    New User

    Status
    Offline
    Join Date
    May 2011
    Posts
    1

    Exclamation urgent help needed!!!

    i have a assigment which has following details:

    a html document with text area to accept integrs(-ve) also with comma and spaces allowed! when the input is submitted it should sort the results in reverse order on click!! the validiation shud be done in javascript for input!! plz help!! its really urgent.... i am a beginner to perl

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: urgent help needed!!!

    Code:
    #! /usr/bin/perl
    use strict;
    use warnings FATAL => qw(all);
    use CGI::Carp qw(fatalsToBrowser);
    use CGI;
    ###############################################################################
    my $q = CGI->new;
    my $string = $q->param('string');
    my @values;
    
    if ($string && $string =~ /^(\s*\d+\s*\,?\s*)*$/) {
    	$string =~ s/\s+//g;
    	@values = split /\,/, $string;
    	@values = sort { $b <=> $a } @values;
    }
    ###############################################################################
    print $q->header;
    
    print <<'HTML';
    <script type="text/javascript">
    	function validate() {
    		var regex = /^(\s*\d+\s*\,?\s*)*$/
    		if (document.form.string.value.search(regex) == -1)
    		alert("Validation failed.")
    		else
    		document.form.submit();
    	}
    </script>
    
    <form name="form" method="post">	
    HTML
    
    {
    local $" = ', ';
    print qq{<textarea name="string">@values</textarea>};
    }
    
    print <<'HTML';	
    <input type="button" name="button" value="process..." onClick="validate()" />
    </form>
    HTML
    ###############################################################################
    exit;
    Last edited by xmassey; 08-24-2011 at 07:17 PM.