Omnimaga
General Discussion => Technology and Development => Web Programming and Design => Topic started by: Munchor on March 14, 2011, 09:12:43 am
-
<!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?
-
Yep, I see it:
<input type="inputtext" size="25" />
<input type ="outputtext" size = 25" />
should be
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
-
Try
function addtext() {
var newtext = document.forms['myform'].elements['inputtext'].value
document.forms['myform'].elements['outputtext'].value += newtext;
}
instead.
-
Yep, I see it:
<input type="inputtext" size="25" />
<input type ="outputtext" size = 25" />
should be
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
That worked perfectly!
Try
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.
-
Also, shouldn't:
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
be written as:
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size="25" />
-
Also, shouldn't:
<input type="text" name="inputtext" size="25" />
<input type="text" name="outputtext" size = 25" />
be written as:
<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. :)
-
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" />
-
I see it, its missing a <b>"</b>
-
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.
-
Chromium doesn't seem to have a problem with it.
I guess its better to do it without spaces, for more compatibility.
-
I have a new question.
How to remove all spaces and lines breaks from a string using regular expressions? Thanks.
-
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).
-
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:
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.
-
\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.
-
\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.
-
You can do [\r\n]+ to capture one or more linebreak characters in a row.
-
inputText = inputText.replace(/[^A-Fa-f0-9]+/g,'').replace(/\s/g,'').replace(/\n|\r|\s/g,'').toUpperCase()
That was my original code yeah, but I have shortened it now.
-
\s captures all linebreaks, tabs, spaces, etc. It's the same as [\r\n \t ... ].
I didn't know that! I just thought it represented a space.
Thanks for the info :)
-
Whitespace includes anything that's blank and a space :D