steveOw steveOw - 6 months ago 15
HTML Question

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

HTML:-

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


JAVASCRIPT:-

function change() {

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

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: https://jsfiddle.net/user/blazeeboy/fiddles/).

This jsfiddle does not work.

It is driving me mad, please help.

UPDATE

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

Change this:

function change() {

to this:

function F_change() {

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

Comments