2

This is actually an Adobe AIR app, but since the problem I'm having is with very basic JavaScript, I thought I should put it here.

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>KM Ciclo de Servicio</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/ciclo.css" rel="stylesheet" type="text/css" />
<script src="script/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function changefield()
{
    #('#ciclo').append('ASD');
}
</script>
</head>
<body oncontextmenu="return false;">
<div id="topMenu">
    <button class="menuItem" id="new" title="Nuevo"><img src="images/new.png" alt="Nuevo"/></button>
    <button class="menuItem" id="save" title="Guardar"><img src="images/save.png" alt="Guardar"/></button>
    <button class="menuItem" id="open" title="Abrir"><img src="images/open.png" alt="Abrir"/></button>
    <input type="text" value="Momento cambiado" onkeypress="changefield()"/>
        <div style="display: inline-block; float: right;">
        Nuevo:
        <button class="menuItem" id="momento">Momento</button>
        <button class="menuItem" id="atributo">Atributo</button>
    </div>
</div>
<div id="main" align="center">
    <div id="ciclo"></div>
</div>
<script src="script/init.js" type="text/javascript"></script>

</body>
</html>    

This is the function I'm trying to call:

<script type="text/javascript">
function changefield()
{
    #('#ciclo').append('ASD');
}
</script>

However, my terminal tells me there's an error on line 20, which is:

<input type="text" value="Momento cambiado" onkeypress="changefield()"/>

The error says:

ReferenceError: Can't find variable: changefield
onkeypress at app:/index.html : 19

I have checked some tutorials on JavaScript functions to make sure (including the one at w3schools), and there doesn't seem to be anything wrong. I am calling the function exactly how these tutorials suggest I do so.

Any ideas on what's going on?

3 Answers 3

5

The proper syntax is this:

function changefield()
{
    $('#ciclo').append('ASD');
}

This was a javascript syntax error:

#('#ciclo').append('ASD');

which caused the changefield function to not be defined.

Sign up to request clarification or add additional context in comments.

1 Comment

You're right! Can't believe I made a typo like that in the code haha. Well, thanks for pointing it out, it works now.
3

Problem might be that jQuery creates $ variable, not #

function changefield()
{
    $('#ciclo').append('ASD');
}

Comments

3

Because # should be $

function changefield() {
    $('#ciclo').append('ASD');
}

This SyntaxError was causing the changefield function to not be created so the inline onkeypress couldn't find it.

6 Comments

Damn but your name is annoying, and essentially impossible to directly respond to on any device other than desktop/laptop.
@DaveNewton Yeah, I'm a troublemaker. Sorry.
Not trouble, just deliberately exclusionary, which somewhat runs counter to the point. Whatever.
@DaveNewton: Deliberately exclusionary? Wow, that sure sounds like trouble to me. I guess I better change it when StackOverflow lets me in 27 days. Till then, we're stuck. :(
Actually no, you can copy your profile from other SE sites to get around that particular hurdle.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.