Author Topic: Javascript Problems  (Read 6751 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Javascript Problems
« on: March 14, 2011, 09:12:43 am »
Code: [Select]
<!DOCTYPE html>
<head>
<script language="javascript" type="text/javascript">
function addtext() {
var newtext = document.myform.inputtext.value;
document.myform.outputtext.value += newtext;
}
</script>
</head>
<body>
<form name="myform">
<input type="inputtext" size="25" />
<input type ="outputtext" size = 25" />
<p></p>
<input type="button" value="Convert" onClick="addtext();">

</form>
</body>
</html>

I have this code which is supposed to pick the text from the inputtext textbox and put it in the outputtext box. It is not working though, any ideas?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Javascript Problems
« Reply #1 on: March 14, 2011, 09:19:38 am »
Yep, I see it:
Code: [Select]
<input type="inputtext" size="25" />
<input type ="outputtext" size = 25" />

should be

Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Javascript Problems
« Reply #2 on: March 14, 2011, 09:21:05 am »
Try

Code: (Javascript) [Select]
function addtext() {
var newtext = document.forms['myform'].elements['inputtext'].value
document.forms['myform'].elements['outputtext'].value += newtext;
}

instead.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Javascript Problems
« Reply #3 on: March 14, 2011, 09:22:43 am »
Yep, I see it:
Code: [Select]
<input type="inputtext" size="25" />
<input type ="outputtext" size = 25" />

should be

Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />

That worked perfectly!

Try

Code: (Javascript) [Select]
function addtext() {
var newtext = document.forms['myform'].elements['inputtext'].value
document.forms['myform'].elements['outputtext'].value += newtext;
}

instead.

The problem was not the function but I'm using that one since it seems more tidy.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Javascript Problems
« Reply #4 on: March 14, 2011, 11:53:28 pm »
Also, shouldn't:
Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
be written as:
Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size="25" />

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Javascript Problems
« Reply #5 on: March 15, 2011, 05:17:22 am »
Also, shouldn't:
Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
be written as:
Code: [Select]
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size="25" />
I don't really know anything of javascript but both 'codes' look the same. ???

EDIT: Oh, I see it now. :)
« Last Edit: March 15, 2011, 05:46:28 am by Stefan Bauwens »


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Javascript Problems
« Reply #6 on: March 15, 2011, 05:25:12 am »
there is a slight difference but does it matter if there are spaces in between the equals sign. i guess it is better coding to have them consistent, either have spaces or don't have spaces.

<input type="text" name="outputtext" size = 25" />
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Javascript Problems
« Reply #7 on: March 15, 2011, 05:35:15 am »
I see it, its missing a <b>"</b>

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Javascript Problems
« Reply #8 on: March 15, 2011, 09:16:57 am »
there is a slight difference but does it matter if there are spaces in between the equals sign. i guess it is better coding to have them consistent, either have spaces or don't have spaces.

<input type="text" name="outputtext" size = 25" />

Does HTML even accept spaces around equal signs? I thought it didn't.




Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Javascript Problems
« Reply #9 on: March 15, 2011, 09:42:44 am »
Chromium doesn't seem to have a problem with it.
I guess its better to do it without spaces, for more compatibility.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Javascript Problems
« Reply #10 on: April 16, 2011, 09:19:02 am »
I have a new question.

How to remove all spaces and lines breaks from a string using regular expressions? Thanks.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Javascript Problems
« Reply #11 on: April 16, 2011, 10:46:32 am »
YOUR_STRING_HERE.replace(/\s/g, '');

/ denotes the start (and end) of a regex expression, \s matches all whitespace, and /g ends the regex and tells it to replace every match (instead of just the first one).




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Javascript Problems
« Reply #12 on: April 16, 2011, 10:55:28 am »
YOUR_STRING_HERE.replace(/\s/g, '');

/ denotes the start (and end) of a regex expression, \s matches all whitespace, and /g ends the regex and tells it to replace every match (instead of just the first one).

What about spaces?

I have this code:

Code: [Select]
inputText = inputText.replace(/[^A-Fa-f0-9]+/g,'').replace(/(\r\n|\n|\r)/gm,"").toUpperCase();
To remove all non-hex characters and linebreaks, does it include spaces? Cos I doubt not.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Javascript Problems
« Reply #13 on: April 16, 2011, 11:02:54 am »
\s captures all linebreaks, tabs, spaces, etc. It's the same as [\r\n \t ... ].

You don't need to do \r\n|\n|\r. That's the same as [\r\n], which is included in \s.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Javascript Problems
« Reply #14 on: April 17, 2011, 05:40:09 am »
\s captures all linebreaks, tabs, spaces, etc. It's the same as [\r\n \t ... ].

You don't need to do \r\n|\n|\r. That's the same as [\r\n], which is included in \s.

I got there, I had a return statement before crashing it all.

The online Z80 Disassembler works well thanks to that.