Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6590421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:17:49+00:00 2026-05-25T17:17:49+00:00

HTML file looks like: <? my $args = shift; ?> . . . <script

  • 0

HTML file looks like:

    <? my $args = shift; ?>
    .
    .
    .
<script type="text/javascript">
function validateInput(value,regex,eid)
{
  var elem;
 alert(eid);
 /* 
  if (value.match(regex) == null) {
     elem = document.getElementById(id);

  }*/
}
</script>
.
    ? foreach my $row (@{$args}) {
    <tr><td><label><?= $row->{field} ?> </label>
    <input onchange="validateInput(this.value,<?=$row->{reg}?>,<?=$row->{id}?>);" 
    type="text" name="<?= $row->{name} ?>" id="<?= $row->{id} ?>" /><span class="small" id="<?= $row->{id} ?>"></span></td></tr>
    ? }

Perl code is:

my $test_tmlp = read_file('registration_form.tmpl');
my @args = ({field => 'First Name',
             name  => 'fn',
             id    => 'fn',
             reg   => '/[a-zA-Z]+/'},
            {field => 'Last Name',
             name  => 'ln',
             id    => 'ln',
             reg   => '/[a-zA-Z]+/'},
            {field => 'Email',
             name  => 'email',
             id    => 'email',
             reg   => '/[a-zA-Z]+/'},
            {field => 'Cellphone',
             name  => 'cellphone',
             id    => 'cellphone',
             reg   => '/[a-zA-Z]+/'},
            {field => 'Coupon Code',
             name  => 'code',
             id    => 'code',
             reg   => '/[a-zA-Z]+/'}  
            );

my $page = build_mt(
        template    => $test_tmlp
    )->(\@args)->as_string;

for some reason, the third parameter that the javascript function get, is always the input HTML object, I’m banging my head against the wall for an hour+ on that with no clue.
could be something with escaping something, but, if I change the ‘id’ hash key to ‘reg’, then the last parameter get passed to the function as it should be…

any idea why this behavior is happening?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:17:49+00:00Added an answer on May 25, 2026 at 5:17 pm

    Let’s see what happens when you invoke validateInput()…

    With HTML rendered with that template, the third parameter in validateInput() is a bareword: it isn’t wrapped in single quotes how it should be, and JavaScript engine should throw an error… The regex doesn’t need single quotes, so if you put the regex as third parameter it is passed to the subroutine.

    I did this little change to your template ( note single quotes around third parameter ):

    ? foreach my $row (@{$args}) {
    <tr><td><label><?= $row->{field} ?> </label>
    <input onchange="validateInput(this.value,<?=$row->{reg}?>,'<?=$row->{id}?>');" 
    type="text" name="<?= $row->{name} ?>" id="<?= $row->{id} ?>" /><span class="small" id="<?= $row->{id} ?>"></span></td></tr>
    ? }
    

    Which yields this HTML:

    <tr><td><label>First Name </label>
    <input onchange="validateInput(this.value,/[a-zA-Z]+/,'fn');" 
    type="text" name="fn" id="fn" /><span class="small" id="fn"></span></td></tr>
    <tr><td><label>Last Name </label>
    <input onchange="validateInput(this.value,/[a-zA-Z]+/,'ln');" 
    type="text" name="ln" id="ln" /><span class="small" id="ln"></span></td></tr>
    <tr><td><label>Email </label>
    <input onchange="validateInput(this.value,/[a-zA-Z]+/,'email');" 
    type="text" name="email" id="email" /><span class="small" id="email"></span></td></tr>
    <tr><td><label>Cellphone </label>
    <input onchange="validateInput(this.value,/[a-zA-Z]+/,'cellphone');" 
    type="text" name="cellphone" id="cellphone" /><span class="small" id="cellphone"></span></td></tr>
    <tr><td><label>Coupon Code </label>
    <input onchange="validateInput(this.value,/[a-zA-Z]+/,'code');" 
    type="text" name="code" id="code" /><span class="small" id="code"></span></td></tr>
    

    Check if it works after this change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My script currently looks like this: <script type=text/javascript> function updateMe(){ var x = 0;
I'm generating an html file which looks like: <tr id=ID001 property1=PROPERTY001><td><input type=checkbox name=row_checkbox_ID001></td><td>...</td><td>...</td></tr> <tr
This is how my text (html) file looks like <!-- | | | This
Absolute beginner question: I have a template file index.html that looks like this: ...
I have a big HTML file that has lots of markup that looks like
It looks like I'm going to have change a .html file over to a
I need to convert a Word document into HTML file(s) in Java. The function
Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
i have a fileinput field for uploading files ... the view file looks like
I have an html file which is shift-JIS encoded (Japanese), and I cannot read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.