There seems to be a glitch in my programming that is preventing it

Can someone please help me troubleshoot this code? I'm unable to figure out what's going wrong. The concept is to take user input, assign it to a variable, and then display a string. However, nothing appears on the screen after entering a name.


Welcome! This platform aims to improve the process of searching for POU Kit Parts:

    <form id="form1">
    <p>Please enter your name:  <input name="name" type="text" size="20"></p></form>
    <p><button onclick="outputname()"> Submit</button></p>

    <script>
    function outputname(){
        var x,name,a,b,answer,y;
        x=document.getElementById("form1");
        y=x.elements["name"].value;
        document.write("Hello " +y+ );
    }
    </script>

Answer №1

Your code contains a syntax error due to an extra + in the statement.

Modify

document.write("hello" +y+ );

to

document.write("hello" + y);

Answer №2

There is an unnecessary + sign in your document.write function.

function displayFullName() {
  var firstName, lastName;
  firstName = document.getElementById("inputForm");
  lastName = firstName.elements["lastName"].value;
  document.write("Hello " + lastName);
}
<form id="inputForm">
  <p>Enter last name: <input name="lastName" type="text" size="20"></p>
</form>
<p><button onclick="displayFullName()">Submit</button></p>

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

The anchor for the circular image is oversized

Currently, I have a PHP code that displays a user's profile picture, and when clicked, it takes them to their own profile. The image is displayed correctly, and the link works fine. However, there seems to be an issue with the area covered by the anch ...

Controller and Directive both setting up isolated scope for a shared element

Having trouble with adding the ng-intro-options attribute to the HTML element. The Issue var App = angular.module('MyApp', ['infinite-scroll', 'angular-intro']); App.controller('MyController', ['$scope', ...

Accessing the value of a field using JavaScript/jQuery

Welcome to my page! I am working on obtaining the current Start and Finish date values. I plan to add a button for users to click, which will then retrieve all dates and display them somewhere on the page. But for now, I just need a way to access the date ...

Utilizing Angular Filters to Assign Values to an Object within a Controller

I have a JSON example with multiple records, assuming that each name is unique. I am looking to filter out an object by name in the controller to avoid constant iteration through all the records using ng-repeat in my HTML. { "records": [ { "Name" : ...

Using an external script to modify or call a Vue.js method

My Vue app is constructed using Webpack and includes a few basic computed properties, such as calculating the sum amount from input values. However, I now require the capability to replace the summation function with one stored in a separate file that is n ...

angular-chart custom tooltip positioning issue

Hello everyone! I'm having trouble fixing the tooltip position when hovering over a point. I've searched through various posts on StackOverflow and have tried all the examples provided in my implementation: https://github.com/chartjs/Chart.js/tr ...

AJAX request is successful, however, the database remains empty with no data being inserted

I have been attempting to utilize ajax and php to insert data into a database, but for some reason, it is not functioning as expected. Despite validating all the itemName, category, and price fields in the html file, the data being inserted into the data ...

Utilize the material-ui dialog component to accentuate the background element

In my current project, I am implementing a dialog component using V4 of material-ui. However, I am facing an issue where I want to prevent a specific element from darkening in the background. While I still want the rest of the elements to darken when the ...

execute javascript code after loading ajax content

Although this question may have been asked before, I am completely unfamiliar with the subject and unable to apply the existing answers. Despite following tutorials for every script on my page, I have encountered a problem. Specifically, I have a section w ...

Is there a way to specifically target the parent input div using event delegation with jQuery?

I'm having trouble inserting values into the input fields for Item Name and Description. See the HTML code below. <div class="input_fields_wrap"> <div class="input_fields_subwrap"><!-- this div is repeatable(dynamic form)--> ...

Conceal the calendar icon from the date-type HTML input field specifically on the Firefox

The situation at hand is quite straightforward. <input type="date /> When viewed on Firefox (both desktop and mobile), it appears as follows: https://i.stack.imgur.com/S2i0s.png While the internet provides a solution specifically for Chrome: ...

Disabling a chosen option within a dropdown menu

`Hello there, I am just starting out with JavaScript and jQuery. Currently, I am developing a web application for ordering food and drinks. I have a dropdown menu for selecting breakfast items and the quantity. When the "add" button is clicked, a dynamic ...

Unable to access the "target" property while transferring a value from child to parent component

Within my project, the student component is considered a child component of the main app component. Inside the template of the student component, there is an input element defined like so: <input type='text' #inputbox (keyup)='onkeyUp(i ...

Can you explain the function of mdLiveAnnouncer in Angular Material and how it operates?

Could someone provide an explanation of $mdLiveAnnouncer using this code snippet? module.controller('AppCtrl', function($mdLiveAnnouncer) { // Making a basic announcement (Polite Mode) $mdLiveAnnouncer.announce('Hey Google'); // ...

Node.js tutorial: Building routes with regex and implementing redirects

Can anyone provide guidance on how to utilize route and redirect URLs with parameters in Node.js using Express? If the URL is xyz/?s=test, it should redirect to indexRouter. If the URL is xyz/, it should also redirect to indexRouter. I'm facing issu ...

Uploading a file to NodeJS via POST and seamlessly forwarding it to another API without storing it on disk

In order to transfer a file from a user through a React UI (with axios), then send it to a NodeJS method via POST using Express, and finally forward the same file directly to another API (.NET WebAPI) without saving it to disk, I am faced with an issue whe ...

What is the best way to send the current ID for data deletion in React?

Here is my current code snippet: var html = []; for (var i = 0, len = this.props.tables.length; i < len; i++) { var id = this.props.tables[i]._id;//._str; html.push( <div key={id} className="col-xs-6 col-md-3"> ...

Is it possible that React.createElement does not accept objects as valid react children?

I am working on a simple text component: import * as React from 'react' interface IProps { level: 't1' | 't2' | 't3', size: 's' | 'm' | 'l' | 'xl' | 'xxl', sub ...

Validator alert for AMP scripts

I have implemented the amp version for my content management system. Since each article has a different body, some include amp-instagram while others include amp-facebook, and so on. In order to cover all bases, I have added both amp-facebook and amp-inst ...

Adjust css rotation to direct an element towards a specific point

Looking to rotate a div towards a point using the CSS 3 transform rotate function. Progress so far: View code on JSFiddle $(document).ready(function(){ var scw,sch,scx,scy; calcCenter(); $(window).resize(function() { calcCent ...