steveOw steveOw - 1 year ago 55
HTML Question

jsfiddle identical(?) fiddles with button to change text one works one does not


<h1 id="title">Javascript example no.2</h1>
<input type="text" id="myTextField"/>
<input type="submit" id="byBtn" value="Change" onclick="F_change()"/>


function change() {

var myNewTitle = document.getElementById('myTextField').value;
if (myNewTitle.length == 0) {
alert('Write Some real Text please.');

var title = document.getElementById('title');
title.innerHTML = myNewTitle;


When user enters text in text field and clicks button the new text will replace the title text.

This jsfiddle works OK (thanks to Emad Elsaid:

This jsfiddle does not work.

It is driving me mad, please help.


I should have spotted the obvious mismatches in function name (F_Change vs. change).

The big lesson for me was to set jsfiddle...javascript...Load Type

from "on load"

to "no wrap - in ".

Thanks to all responders.

Answer Source

Change this:

function change() {

to this:

function F_change() {

And change Javascript -> Load Type to "No Wrap - in <head>"