The onchange event is failing to trigger any JavaScript function

I am facing an issue where the onchange event of a dropdown menu is not triggering at all. I even tried redirecting it to a simple JavaScript function for testing purposes, but that didn't work either. I'm struggling to find a solution. Below is the sample code I have been working with:

HTML:

    <div id="Category_and_Food">
            <form>
                <select id="categories" onchange="tested()">
                    <option value = "">Please select a category</option>
                    <option value="Appetizers">Appetizers</option>
                    <option value="Entree">Entree</option>
                    <option value="Specials">Specials</option>
                    <option value="Drink">Drinks</option> 
                    <option value="Meat">Meat</option>
                    <option value="Soup">Soup</option>
                </select>
            </form>
        <br />
        <div id="cat_display"><b>Please select a category above</b></div>   
    </div>

Javascript:

<script type = "text/javascript">
function tested()
{
var x = document.getElementById("categories").value;
document.getElementById("cat_display").innerHTML = x;
{
</script>

Previously, I also attempted using the onchange event as onchange="tested(this.value)" with the function being adjusted accordingly.

Answer №1

You're facing a tiny error with a misplaced }:

function verified()
{
    var y = document.getElementById("sections").value;
    document.getElementById("sec_display").innerHTML = y;
} // <----

For instance: http://jsfiddle.net/K9cde/2/

Make sure to utilize a tool like JSLint for identifying syntax errors in your code.

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

Leveraging both onmouseover and onmouseout for container expansion

My goal is to utilize JavaScript along with the HTML events "onmouseover" and "onmouseout" to create a dynamic container. Essentially, I want the container to act as simply a heading when the mouse is not hovering over it, but expand to display additional ...

How to use AJAX to dynamically populate an HTML form with data retrieved from a PHP query结果

I'm having trouble populating a form with values after running a simple search. When I execute the script, I either receive an "undefined" response or nothing at all when I try alert(data);. search.php <?php include_once 'config/config.php&a ...

Having trouble selecting a default option in a dynamically populated select dropdown using ng-model in the dropdown

For my Angularjs application, I needed to dynamically return a select drop down with its selected option. To accomplish this, I implemented the following function: function getCellRendererMapping(data) { if (data.order == 6) { return funct ...

What is the most efficient method for storing and retrieving numerous DOM elements as JSON using the FileSystem (fs) Module in Node.js?

Is there a way to efficiently save dynamically added DOM elements, such as draggable DIVs, to a file and then reload them later on? I am looking for the most organized approach to achieve this. ...

create new Exception( "Invalid syntax, expression not recognized: " msg );

Can someone assist me in identifying the issue at hand? Error: There seems to be a syntax error, and the expression #save_property_#{result.id} is unrecognized. throw new Error( "Syntax error, unrecognized expression: " msg ); Here is the c ...

Each time the toggle is switched, an additional AJAX request is sent to the PHP document

I've been working on a function that sends data to a PHP file, which then processes the data. The PHP part works fine, but I'm having issues with the jQuery side of things. Each time I click on a ".work" element and trigger the toggle function, a ...

Is it possible to utilize JavaScript for transmitting and storing data on a server?

Consider this scenario: When you submit a query on stackoverflow, the data you provide is entered into a text field. This information is then transmitted to the server for storage and eventual display to the user. Is it possible to code the functionality ...

Using Node.js and JWT: A guide to securely storing and using access tokens in the Authorization header

Has anyone encountered this issue before? I've searched extensively online but haven't found much information on the topic. I'm relatively new to using node and JWTs, and my goal is to generate a JWT and store it in the Authorization header ...

Leveraging the 'clicked' variable in the Ajax success function

I am struggling to access a dynamic variable from the CSS class in an Ajax request. I have attempted the following without success. function watchlist($video_id, $user_id){ $.ajax({ url: "watchlist.php", data: {video_id : $video_id, u ...

Expanding and collapsing UI elements within an ngRepeat loop in AngularJS

I have been attempting to incorporate collapsible panels within an ngRepeat loop. Below is the code I have been using: <div class="panel panel-default" ng-repeat="element in elements"> <div class="panel-heading"> ...

"Sending data with jQuery by encoding an array in PHP and converting it

This question has been raised in various forms before. I am facing a challenge when it comes to transferring data from a JSON encoded array to another page on my domain. Below is the PHP code snippet: <?php $json_results = json_encode($results); ...

A step-by-step guide on increasing native Time variables in JavaScript

How can I dynamically and repetitively add time (both hours and minutes) in JavaScript to effectively increment a date object? There are times when I need to add minutes, or hours, or a combination of both - and I want the resulting total time to be return ...

Alter the entity type when passing it as a parameter

Trying to alter the Entity type, I am invoking a function that requires two parameters - one being the entity and the other a location. However, when trying to assign a Type for the first entity, it throws an error: Error: Argument of type 'Node<En ...

Display information in a div container from other pages on the website

I am attempting to dynamically load content into a div in Index based on the selection made in a dropdown box, but it doesn't seem to be working correctly. I have created a simple example using four pages to demonstrate the issue: Index.html one.html ...

What is the method for submitting a POST request with a JSON body that consists of only a string, without any key-value pairs included?

There was a developer who, not knowing the correct JSON format for key-value pairs, created a JSON body that looks like this: { "dog" } Instead of { "dog": "dog" } I must send the request from a JavaScript file, and the body needs to be in JSON f ...

Activate validation when the scope of a custom validator is modified

Consider a scenario where we have a custom validator with an input as the attribute's value. app.directive('inputRequired', function() { return { require: 'ngModel', scope: { inputRequired: '=& ...

How can I achieve a smooth opacity transition without using jQuery?

Although I understand that JQuery offers functions for this purpose, I am interested in finding a solution using only pure javascript. Is there a way to change the CSS opacity setting over time? Perhaps utilizing a unix time stamp with millisecond precisi ...

Interruption of client-side JavaScript by the ASP timer tick event

Exploring the Situation In the realm of web development, I find myself immersed in creating a web application dedicated to monitoring various services. Each service is equipped with an UpdatePanel, showcasing status updates along with interactive buttons ...

Functionality Issue: Submit Button Not Working on Designed Form Select

Through dedication and hard work, I managed to create a customized form with images that display correctly in Firefox, Chrome, and Internet Explorer's compatibility mode. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

Do you have an index.d.ts file available for canonical-json?

I am currently working on creating an index.d.ts file specifically for canonical-json. Below is my attempted code: declare module 'canonical-json' { export function stringify(s: any): string; } I have also experimented with the following sn ...