Code works on JS fiddle but not on my website

Charkel

I am trying to make a search history log using Local Storage in HTML and I am currently trying to understand how to use the local storage function. Now I have run into an odd problem.

This example works great: http://jsfiddle.net/hr3xQ/17/

But when I try to put it together on my server nothing happens when I try to run the code

    <!doctype html>

<html lang="en">
<head>
    <title>Test</title>
    <meta charset="utf-8>
        <link rel="stylesheet" type="text/css" href="test.css">
<script type='text/javascript'> 

$(function () {

    $("#submit").click(function () {
        var name = $("#name").val();
        localStorage.setItem('username',name);
        alert(localStorage.getItem('username'));

    });
});  

</script>

</head>
<body>

    name:
<input type="text" id="name">
<br/>
<br/>
<input type="button" id="submit" value="store in local">

</body>
</html>

What am I doing wrong? I'm not very used to web-programming.

AstroCB

You'll need to include jQuery if you want to use jQuery.

In JSFiddle, you get a nice little toggle that allows you to select the frameworks/libraries you'd like to include.

However, when you move your code, the jQuery inclusion doesn't come along with you. You need to either download it or include it via a script tag in the head (do it above your other script so that jQuery loads before you try to use it:

<script src="//code.jquery.com/jquery-latest.min.js"></script>

This is a very common problem: whenever nothing happens, it's a good idea to check your browser's console. For not including jQuery, you'll often get something like this:

ReferenceError: $ is not defined

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Code works on JS fiddle but not on my website

From Dev

Code works on JS Fiddle but not in Chrome or Firefox

From Dev

Code not working on JS Fiddle

From Dev

JS code working on my page but does not on fiddle, why?

From Dev

CSS Calc returning 0 but works in my fiddle

From Dev

Code works on fiddle but not when I do /show

From Dev

Js does not work as expected on my website even it works on codepen

From Dev

SQL query works in Fiddle but got error in actual php code

From Dev

Javascript works in JS Fiddle but doesn't work in Chrome/IE

From Dev

Javascript works in JS Fiddle but doesn't work in Chrome/IE

From Dev

example works in js-fiddle but not in self-made page

From Dev

Fiddle script not working on website

From Dev

HTML works in Fiddle but not locally

From Dev

Does changing code of aspx in published website works?

From Dev

A suspected code uploaded in my website

From Dev

Code works on codepen but not on my site

From Dev

Powershell code Telnet website or ping website If there is no connection Works restart iis

From Dev

Why is my fiddle not behaving correctly?

From Dev

Installing JS code on Shopify or Website

From Dev

Does my code using Node.js and callback function works same as Java Threads?

From Dev

Does my code using Node.js and callback function works same as Java Threads?

From Dev

How could I fix my js code in order it works with Bootstrap 4 collapse-div?

From Dev

jquery works not properly on first click, but in fiddle it does

From Dev

ExtJS 5 Charts: Chart works in fiddle but not in application

From Dev

Script working in JS Fiddle, but not in browser

From Dev

API call in a react JS fiddle

From Dev

Styling php code for showing on my website

From Dev

Add custom html code snippet to my website

From Dev

My WordPress Website Show a line of code on the top

Related Related

  1. 1

    Code works on JS fiddle but not on my website

  2. 2

    Code works on JS Fiddle but not in Chrome or Firefox

  3. 3

    Code not working on JS Fiddle

  4. 4

    JS code working on my page but does not on fiddle, why?

  5. 5

    CSS Calc returning 0 but works in my fiddle

  6. 6

    Code works on fiddle but not when I do /show

  7. 7

    Js does not work as expected on my website even it works on codepen

  8. 8

    SQL query works in Fiddle but got error in actual php code

  9. 9

    Javascript works in JS Fiddle but doesn't work in Chrome/IE

  10. 10

    Javascript works in JS Fiddle but doesn't work in Chrome/IE

  11. 11

    example works in js-fiddle but not in self-made page

  12. 12

    Fiddle script not working on website

  13. 13

    HTML works in Fiddle but not locally

  14. 14

    Does changing code of aspx in published website works?

  15. 15

    A suspected code uploaded in my website

  16. 16

    Code works on codepen but not on my site

  17. 17

    Powershell code Telnet website or ping website If there is no connection Works restart iis

  18. 18

    Why is my fiddle not behaving correctly?

  19. 19

    Installing JS code on Shopify or Website

  20. 20

    Does my code using Node.js and callback function works same as Java Threads?

  21. 21

    Does my code using Node.js and callback function works same as Java Threads?

  22. 22

    How could I fix my js code in order it works with Bootstrap 4 collapse-div?

  23. 23

    jquery works not properly on first click, but in fiddle it does

  24. 24

    ExtJS 5 Charts: Chart works in fiddle but not in application

  25. 25

    Script working in JS Fiddle, but not in browser

  26. 26

    API call in a react JS fiddle

  27. 27

    Styling php code for showing on my website

  28. 28

    Add custom html code snippet to my website

  29. 29

    My WordPress Website Show a line of code on the top

HotTag

Archive