My html form action shows javascript code in the browser

html form action=javascript
javascript form action submit
how to pass parameters in form action in html
html form post example
html form design examples with code
form action= # means
form method=post'' action
html submit button action

I have the following code written in html

<form id = "name" action="../js/customerData.js">
    First name: <input id = "firstName" type="text" name="firstName" placeholder="First Name"><br>
    Last name: <input id = "lastName" type="text" name="lastName" placeholder="Last Name"><br>
    <input type="submit" name="FLnames" id="FLnameVar" value="Submit">

And this code written in javascript which is what the form action calls

firstName = document.getElementByName("firstName");
lastName = document.getElementByName("lastName");

However, when I submit the html form the browser just displays the javascript. Does anyone know why this is and how I can fix it? Thanks

Your form action is sending a post/get request to "../js/customerData.js"

your url would look like this


Usually you would use a server side language to handle the data from the URL where you could get those values through $_POST["first-name"] (PHP)

If you sending it to a javaScript file it is not "parsed" The browser sees it as a text file .In order to get the Javascript to work , make it an html file (or server file ) and tell the browser you running a script with the script tag

        <script type="text/javascript">          

Alternatively if you using JS use the


in form action i.e (<form id = "name" action="!#">)

then use an JavaScript event listener to listen for the form submit

var ele = document.getElementById('name');
    ele.addEventListener("submit", callback, false);  //Modern browsers
}else if(ele.attachEvent){
    ele.attachEvent('onsubmit', callback);            //Old IE

In the callback use JS to get the elements Value

function Callback ()
let fname =  document.getElementById("firstName").innerHTML;
// then you use the value to post 

The last stage using this method to save it is to use something like ajax to send to a server

I hope this helps you .

form action with javascript, The form action does not seem to be doing anything in IE, my question The best is to just set form action to your PHP script; if you need to do anything show 8 more comments Tested in Firefox, Chrome, Edge and Safari --> of the html document and them in the action just call the javascript function. Whenever I want to run a JavaScript code on them they show me the raw code instead of executing it. Exactly what I wrote in my Editor will be shown in the browser screen. Hope someone can help. Edit. Hey, am not using wordpress. Sorry that I didn't put the code here. Here is the code in my text Editor: <Script> Document.write("hello world

An HTML form submits its data to a resource that can provide a response. Since your form submits directly to a .js file, the browser just displays it because the HTML page that submitted the data is no longer loaded in the browser. There are no elements to get and no document to scan.

You need to post your form data to a resource that can process HTTP requests and provide an HTTP response like a .php file.

See this for an overview of processing form data (scroll to the "On the server side: retrieving the data" section). It gives several examples in various server-side languages.

Also, getElementByName() doesn't exist, it's getElementsByName(). But, you won't be able to use that when looking at the submitted form data because (again) that document and all of its elements will no longer be loaded. Instead, when processing form data, you must query the request object.

HTML form action Attribute, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� JavaScript allows you to modify the action field of an HTML form dynamically. This article shows you how to do it. Multiple submit buttons. It is possible to have more than one submit button in a form. See the article on HTML form submit button for details. The example below shows how to switch the action field based on the submit button pressed.

What Form Method Tells Your Web Browser In HTML: An Easy , Tells the browser how to send form data to a web server. onSubmit, Runs a script when the Submit button is clicked. onReset, Runs a script when the Reset button � Code inspectors are designed for debugging HTML and Javascript. They do so by showing the live DOM object of the web page. That means it reveals HTML code of everything you see on the page, even if they're generated by Javascript. Some inspectors even shows the code inside iframes.

Your first form, The first article in our series provides you with your very first A web form's HTML is made up of one or more form controls The method attribute defines which HTTP method to send the data On the server side, the script at the URL " /my-handling-form-page Tools and testing; Cross browser testing. Submitting a form normally means that the browser navigates to the page indicated by the form’s action attribute, using either a GET or a POST request. But before that happens, a "submit" event is fired. This event can be handled by JavaScript, and the handler can prevent the default behavior by calling preventDefault on the event object.

Sending form data, An HTML form on a web page is nothing more than a convenient user-friendly The GET method is the method used by the browser to ask the server to send back The data is appended to the URL as a series of name/value pairs. that look like executable code (such as JavaScript or SQL commands). To add JavaScript to a Web page, all you have to do is embed JavaScript code in an HTML file. Below the line in which you embed the JavaScript code, you can reference, or call, that JavaScript code in response to an event handler or an HTML link. You have two choices when it comes to embedding JavaScript code in an HTML file:

Forms and Form Fields :: Eloquent JavaScript, Multiline text fields have their own tag, <textarea> , mostly because using an Unlike most elements in an HTML document, form fields can get keyboard focus. that the browser navigates to the page indicated by the form's action attribute, using The following example shows a text field and a counter showing the current� This will help you to setup a local web server known as lite-server with VS Code, and also guides you to host your static html files in localhost and debug your Javascript code. 1. Install Node.js. If not already installed, get it here. It comes with npm (the package manager for acquiring and managing your development libraries) 2.