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

  • Home
  • SEARCH
  • 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 1098273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:33:19+00:00 2026-05-17T00:33:19+00:00

It is always good to separate presentation layer and behaviour between HTML and Javascript

  • 0

It is always good to separate presentation layer and behaviour between HTML and Javascript based on head first book.

They tell me not to do:

<textarea onclick="showAlert()"></textarea>

But instead, do below:

The example below separate the behaviour from HTML code (structure).

<html>
<head>

<script type="text/javascript">
window.onload = init;

function init() {
  $('txt_area').onclick = showAlert;
}

function showAlert(say) {
  alert(say);
}
</script>
</head>
<body>
<textarea id="txt_area"></textarea>
</body>
</html>

This allows HTML (structure) to look clean and “behaviour” part is initialized in init() function when page loads. I understand that so far.

But then I wonder how am I supposed to pass an argument to showAlert() function???

Below does not work, it will call the showAlert() as soon as the page loads and this is not what I want to because it needs to be fired onclick.

function init() {
  $('txt_area').onclick = showAlert("hello");
}

Is it possible to pass arguments to showAlert() function but still separate the behaviour and structure?

UPDATE

Forgot to mention.. I’m using prototype.

  • 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-17T00:33:20+00:00Added an answer on May 17, 2026 at 12:33 am

    Wrap your code in a function.

    $('txt_area').onclick = function() {
        showAlert("hello");
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I'm using google translate) I separate my HTML and PHP , just for good
As far as I understand WebRequest.PreAuthenticate is almost always good. If I enable it
I have always been a good boy when writing my classes, prefixing all member
Good morning, I'm trying to connect to a site using SSL and always receive
Good day, I try to start new Activity from another. But it always crashed.
Is this legal and/or good practice? #define SOFTWARE_VERSION_NUMBER 7.0v1.1 Want struct to always contain
I'm cleaning up some Jquery code. I always read, chaining is good for performance.
So we all know that you should always, not only in PHP, separate code
I am building my first complicated website. Everything I code looks good in Google
I always read that one reason to chose a RESTful architecture is (among others)

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.