Click on the button without any reaction

I'm having trouble with the button.

When I click on the button with ng-click="goSearchTitle()", nothing happens.

Any idea why it's not working?

    <body ng-app="myapp">

    <div ng-contoller="searchbyTitle">
        <h3>Searching by Title</h3>
        <div>
            <input type="text" id="searchTitle" placeholder="Enter a title" ng-model="searchTitle"/>
            <button type="button" id="goSearchTitle" ng-click="goSearchTitle()">Search</button>
        </div>

    </div>

    <script>
        angular.module("myapp", []).controller("searchbyTitle", function($scope, $http) {
            $scope.goSearchTitle = function(){
                alert($scope.searchTitle);
            }
        });
    </script>
    </body>

Answer №1

The name of your application is incorrect.

<body ng-app="myapp">

If not corrected, Angular will generate an injector module error. It is advisable to always check the console for errors in order to gain a better understanding.

Answer №2

You made a typo at ng-contoller, it should be ng-controller

var myApp = angular.module("myapp", []);
myApp.controller("searchbyTitle", function($scope, $http) {
  $scope.goSearchTitle = function() {
    alert($scope.searchTitle);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="myapp">
  <div ng-controller="searchbyTitle">
    <h3>Search by Title</h3>
    <div>
      <input type="text" id="searchTitle" placeholder="Enter a title" ng-model="searchTitle" />
      <button type="button" id="goSearchTitle" ng-click="goSearchTitle()">Search</button>
    </div>
  </div>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for saving and retrieving req.user using JsonwebToken

Looking for ways to store and retrieve req.user using JsonwebToken in my booking application built with Node. I need to fetch the user information who booked a product and display it on the admin portal. .then((user) => { const maxAge = 3 * 60 * ...

Set element back to its default state

When working with JavaScript, how do you go about restoring the default behavior of a DOM element's event handler? For instance, let's say you've set the onkeypress event for an input element: elem.onkeypress = function() { alert("Key pres ...

Sending information from Ajax to PHP

Could anyone please explain the script provided above to me? I am attempting to pass the value of $user data so that I can utilize $_REQUEST['user'] within sort.php, but I am encountering difficulties. It seems to be passing in a long URL. $(fun ...

How to make a specific table row stand out using AngularJS and CSS

Can you provide advice on how to highlight a specific row in a table? I have a table along with some angular code snippets. Here's an example: angular.module('myApp', []).controller('myTest', function($scope) { var data = []; ...

Using TypeScript with Watermelondb

I'm currently developing a React App and I want to implement Watermelondb for Offline Storage, but I'm unsure about using it with TypeScript. I have already set up the database and created Course and Lesson model files from the Watermelondb libra ...

Tips for retrieving the MenuItem name upon click event using Menu and MenuItem components in Material UI React

Utilizing MaterialUI's Menu and MenuItem components in a React project, I am looking to display the name of the menu item upon clicking on it. Upon inspecting event.currentTarget in console.log, it returns the entire list item: ListItem Image attache ...

What is the quickest method for importing React.js Material Icons in a single line of code?

While working on my initial react.js project as a beginner, I encountered the frustration of having to import Material UI icons individually. This process made my code unnecessarily long and required me to repeatedly visit the browser to copy the icon li ...

What is the alternative method in JavaScript for locating items instead of using indexOf?

I have a set of paths in an array. Some paths are classified as constants while others are labeled as dynamic. A constant path would be something like "/booking-success", whereas a dynamic path could be something like '/arrival/view/:job_or ...

Efficiently pinpointing the <div> element with precision using jQuery

I am building an interactive quiz for users of my app. The questions are table based, and can be answered "yes," "no," or "maybe." If the user answers "no" or "maybe," I would to slide open an informational panel that lives beneath the table. Here is the ...

Having trouble directing the focus on an HTML5 element using Javascript and Selenium webdriver

On my website, I have a specific structure in place: https://i.sstatic.net/bZhHvNlU.png Whenever the button with the ID addProfButton is clicked in the following manner: Using JavaScript: document.getElementById("addProfButton").click(); Usi ...

Troublesome issue with the Focus() function in JavaScript

I'm having trouble setting the focus on a textbox with the id "txtCity." document.getElementById("txtCity").focus(); Any suggestions on how to make it work? ...

VueJS form validation does not account for empty inputs in both fields

One of the challenges I'm facing is generating a form with Vue.js using the input fields below: { name: 'first_name', type: 'text', label: 'First Name', placeholder: 'First Name', ...

Simulating SOAP requests using the Nock library

I have a project in progress involving a node application that interacts with soap services. To handle parsing of JSON into a valid SOAP request and vice versa for the response, I am using the foam module. Everything works smoothly when communicating with ...

The compatibility between Laravel's @vite('resources/js/app.js') and the froala editor plugin seems to be causing issues

I have incorporated a Vue.js based commenting system and inbox messages system in my Laravel website. Additionally, I am utilizing a wysiwyg editor (Froala Editor) in my forms for uploading projects. The issue I am facing is that the Froala Editor does no ...

Elegant switch in jQuery

I am trying to use jQuery to create an animated toggle button. The toggle function is working correctly, but I am having trouble adjusting the speed and smoothness of the animation. After researching different methods and attempting to modify the values i ...

Is it possible to store an HTML element tag in a variable?

I've been learning JavaScript on w3schools and freecodecamp, but I stumbled upon something in w3schools that has me puzzled. Can someone please explain why this particular code snippet works? The variable "text" is declared as containing the string " ...

Troubleshooting $routeProvider issues in Angular

This is the content of my app.js: var cricketapp = angular.module('cricketapp', ['ngCookies']). config(['$routeProvider', function($routeProvider, $httpProvider, $cookies){ $routeProvider. when('/ ...

Guide on detecting and capturing a change in location history event

My main goal is to capture router change events outside of the NextJS framework, not within it. The application I have developed using NextJS includes some code that operates independently of the NextJS context. This code needs to be able to detect navigat ...

retrieve the value of an HTML element once it has been modified

When I am working in a view, I encounter an issue where I need to retrieve the value of an HTML input box after it has been changed. Initially, the page loads with the following code: <input id="input_one" type="text" value = "apple" /> Upon loadin ...

A nifty little JavaScript tool

Recently, I created a bookmarklet that opens a new window with a specified URL and passes variables to a PHP script using the GET method. However, I now require it to load the same PHP script and pass the same variables but within a div element this time. ...