Forum Moderators: open

Message Too Old, No Replies

Javascript just not running and acting like regular text

Not much more can be said....

         

Spiceydog

2:29 am on Jun 26, 2008 (gmt 0)

10+ Year Member



I have a javascript code I just got ahold of and fixed up. What it is supposed to do is add a new input bar everytime you click the button. I think the script itself works but for some reason when you view it in a website it reads:
function addtrack(){    var addTrack = document.createElement("track"); input.type="text"; input.name="track"; input.size="20"; input.maxlength="50"; }

Here is basically what the page is:
<html>
<script language="javascript">
function addtrack(){
   var addTrack = document.createElement("track");
input.type="text";
input.name="track";
input.size="20";
input.maxlength="50";
}
</script>
<body>
Track:
<input name="track" type="text" size="20" maxlength="50">
<button onclick="track();">MORE TRACKZ!</button>
</body>
</html>

Thanks in advance!

daveVk

4:58 am on Jun 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TRY

<html>
<head>
<script language="javascript">
function addtrack(){
var addTrack = document.createElement("track");
addTrack.type="text";
addTrack.name="track";
addTrack.size="20";
addTrack.maxlength="50";
.. more code here to add addTrack to page ..
}
</script>
</head>
<body>
Track:
<input name="track" type="text" size="20" maxlength="50">
<button onclick="addtrack();">MORE TRACKZ!</button>
</body>
</html>

Spiceydog

5:06 am on Jun 26, 2008 (gmt 0)

10+ Year Member



Still not working. I did exactly what you said and I'm still getting the same thing (I don't want to exactly call it an error....):
function addtrack(){    var addTrack = document.createElement("track"); addTrack.type="text"; addTrack.name="track"; addTrack.size="20"; addTrack.maxlength="50"; }

I get that at the top of the page.

poppyrich

5:06 am on Jun 26, 2008 (gmt 0)

10+ Year Member



The script itself ain't working - something happens onclick, yes, but not what you want. So working, no.

Try this and see how it works for you. It will probably still need work in placing the input where you want it to go but it at least should add a text input to the page putting you halfway there.

Here is basically what the page is:
<html>
<script language="javascript">
function makeaddtrack(){
var addTrack = document.createElement("input");
addTrack.type="text";
addTrack.name="track";
addTrack.size="20";
addTrack.maxlength="50";
document.body.appendChild(addTrack);
}
</script>
<body>
Track:
<input name="track" type="text" size="20" maxlength="50">
<button onclick="makeaddtrack();">MORE TRACKZ!</button>
</body>
</html>

Spiceydog

5:17 am on Jun 26, 2008 (gmt 0)

10+ Year Member



Well I got my first problem working but now the button isn't doing what it is supposed to do. It just doesn't create an input bar when clicked. I did what you said Poppy but it still doesn't work.

[edited by: Spiceydog at 5:23 am (utc) on June 26, 2008]

daveVk

7:28 am on Jun 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adding the head tags, may not be issue but won't harm.

Spiceydog

7:34 am on Jun 26, 2008 (gmt 0)

10+ Year Member



Unfortunately I already tried that and it didn't work. Lucky for me I finally googled the right combination of words <snip>
works perfectly! wooooo

[edited by: engine at 9:57 am (utc) on June 27, 2008]
[edit reason] No urls, thanks [/edit]