-1

Here is my piece of 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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Shout!</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

var status=1;
function action() {



if(status==1) {
$("#Layer1").hide("slow");
$("#Layer3").hide("fast");
$("#Layer4").hide("slow");
$("#close").attr("src","open.jpg");
status=0;

}

else if(status==0) {
status=1;
$("#Layer1").show("slow");
$("#Layer3").show("fast");
$("#Layer4").show("slow");
$("#close").attr("src","close.jpg");

}




}


function sendline() {

$("#msg").val(" ");

}

function type() {
var text=$("#msg").val();

$("#Layer6").html(text);

}

</script>
<style type="text/css">
<!--
    body {
 background-color: #000000;
    }
    #Layer1 {
 position:absolute;
 width:200px;
 height:115px;
 z-index:1;
 left: 179px;
 top: 3px;
    }
    #Layer2 {
 position:absolute;
 width:69px;
 height:64px;
 z-index:2;
 left: 570px;
 top: 543px;
    }
    #Layer3 {
 position:absolute;
 width:124px;
 height:22px;
 z-index:3;
 left: 473px;
 top: 474px;
    }
    .style1 {
 color: #FFFFFF;
 font-family: "Segoe UI";
 font-weight: bold;
    }
    #Layer4 {
 position:absolute;
 width:72px;
 height:27px;
 z-index:4;
 left: 744px;
 top: 485px;
    }
    #Layer5 {
 position:absolute;
 width:274px;
 height:70px;
 z-index:5;
 left: 422px;
 top: 62px;
    }
    #Layer6 {
 position:absolute;
 width:638px;
 height:356px;
 z-index:5;
 left: 272px;
 top: 105px;
    }
-->
</style></head>

<body>
<div class="style1" id="Layer3">
<textarea id="msg" style="height:50px;width:250px" rows="10" cols="80" onkeyup="type()"></textarea></div>
<div id="Layer1">Hello World!<img src="body.jpg" alt="Shout !" width="842" height="554" /></div>
<div id="Layer2"><img src="close.jpg" id="close" width="63" height="64" OnClick="action()"/></div>
<div id="Layer4">
<input type="button" value="Send Line" onclick="sendline()" /></div>
<div id="Layer6" style="color:#FFFFFF;"></div>
</body>
</html>

I'm facing a problem with the type() function.Its simply not running

Any advice on how to get it rnnning?

Thanks!

11
  • You're using jQuery in combination with inline event handlers? Blasphemy! Commented Aug 7, 2010 at 18:56
  • umm,the sendline() function works just fine! :S Commented Aug 7, 2010 at 18:57
  • It works fine on my desktop! :S . And what's the problem if we use it that way ? I've seen such examples in books like AJAX and jQuery for dummies. It should work Commented Aug 7, 2010 at 19:01
  • There's no real problem with inline event handlers, except it doesn't really follow with unobtrusive JavaScript and a clear separation of behavioural logic from markup. In addition, it registers more event handlers with the DOM than jQuery and this I believe makes it more prone to memory leaks when manipulating the DOM, an example of which might be removing elements from the DOM without not having first detached the event handlers registered for them. Commented Aug 7, 2010 at 19:09
  • Thanks! is there any way that would help me to do the same thing ? i mean can i use jquery and javascript together ? pardon me! but i'm a beginner! Commented Aug 7, 2010 at 19:10

2 Answers 2

1

Your function is running, however it's throwing an error because of the function name:

Uncaught TypeError: string is not a function

or in Firefox:

type is not a function

In short, you can't use type as a function name here, you just need to give it a slightly different name, for exampled typed.

Here's your code only changing the function name, working :)

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

Comments

1

Rename your type function to something else (try somethingElseThanType just to test), and it should work

Comments

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.