473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does Split() work in Mozilla?

My goal is to accept input from the user into a text box and then
parse the data using split(). The first step is this tiny program to
test the split() function. It runs in IE, but in Mozilla it just
hangs and keeps loading forever. I checked around on the web and in
USENET, but I haven't seen any mention of split() not working in
Mozilla. Thoughts? Thanks in advance.

<HTML>
<HEAD>
</HEAD>
<SCRIPT language="JavaS cript">
<!--

function one()
{

var1 = "one, two, three, four"
var2 = var1.split(",")

document.write( "var1=" + var1 + "<br>");
document.write( "var2 has " + var2.length + " elements:<br>") ;

for (var i=0; i < var2.length; i++) {
document.write( "Array Item #" + i + "=" + var2[i] + "<br>");
}

}

//-->

</SCRIPT>
<BODY>

<FORM name="oneForm">

<INPUT onclick="javasc ript:one()" type=button value="Does split() work
in Mozilla?"></INPUT><BR>

</FORM>

</BODY>
</HTML>
Jul 23 '05 #1
4 3596
On 4 May 2004 05:10:32 -0700, Brian Glen Palicia <bp******@nls.n et> wrote:
My goal is to accept input from the user into a text box and then
parse the data using split(). The first step is this tiny program to
test the split() function. It runs in IE, but in Mozilla it just
hangs and keeps loading forever. I checked around on the web and in
USENET, but I haven't seen any mention of split() not working in
Mozilla.
That's because it does. Your code is the problem. I've included comments
below. Most correct your HTML, which won't fix the problem, but you should
heed anyway.

HTML documents should include a document type declaration (DTD). See:

<URL:http://www.w3.org/TR/html401/struct/global.html#h-7.2>
<HTML>
<HEAD>
Valid HTML documents must include a TITLE element.
</HEAD>
<SCRIPT language="JavaS cript">
There are two problems here:

1) The SCRIPT element must either appear inside the HEAD or the BODY
section. It is invalid anywhere else.
2) The SCRIPT element requires the type attribute. Furthermore, the
language attribute is deprecated and shouldn't be used anymore.

Move the block into the HEAD section and replace the start tag above with

<script type="text/javascript">
<!--
The practice of script hiding is obsolete. Remove the SGML comment
delimiters.
function one()
{

var1 = "one, two, three, four"
var2 = var1.split(",")
You really should use better names. You should also declare these with the
var keyword, otherwise they become global variables (which you don't want).
document.write( "var1=" + var1 + "<br>");
document.write( "var2 has " + var2.length + " elements:<br>") ;

for (var i=0; i < var2.length; i++) {
document.write( "Array Item #" + i + "=" + var2[i] + "<br>");
}
You should never use document.write( ) once a page has loaded. It causes
the current information (including all JavaScript variables) to be trashed
and the page is completely replaced. If you want to debug your code,
either use an alert box, a TEXTAREA element, or the DOM to modify the page.
}

//-->
Remove this.
</SCRIPT>
<BODY>

<FORM name="oneForm">
A FORM element is only necessary in two instances:

1) If you intend to submit data to a server.
2) If you want to obtain references to form controls and you need to
support old browsers

You do neither here, so it's superfluous.
<INPUT onclick="javasc ript:one()" type=button value="Does split() work
in Mozilla?"></INPUT><BR>
Two issues here:

1) The INPUT element is empty. That is, it doesn't need, nor should it
ever have, a closing tag.
2) Specifiying "javascript :" in an intrinsic event is practially
meaningless in all but one browser, and even then, it's unnecessary.
Remove it.
</FORM>

</BODY>
</HTML>


Try this, and you'll see that Mozilla has no problems with split():

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>Test</title>

<script type="text/javascript">
function one() {
var output = document.getEle mentById( 'output' );

var var1 = "one, two, three, four";
var var2 = var1.split(",")

output.value = "var1 = " + var1 + "\n";
output.value += "var2 has " + var2.length + " elements:\n\n";

for( var i = 0, n = var2.length; i < n; ++i ) {
output.value += "Array Item #" + i + "=" + var2[ i ] + "\n";
}
}
</script>
</head>

<body>
<div>
<textarea id="output" rows="5" cols="80"></textarea><br>
<button type="button" onclick="one()" >Test split()</button>
</div>
</body>
</html>

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
Wow. There was so much good information there, all of it really helped
a lot. Thanks so much. Now I just need to figure out how to build a
program to parse data from the textarea. :grin:

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Brian Palicia wrote:
Wow. There was so much good information there, all of it really helped
a lot. Thanks so much. Now I just need to figure out how to build a
program to parse data from the textarea. :grin:

Use the same technique, just pass the textarea object to the function:

function getWords(formTe xtObject) {
return formTextObject. value.split(" ").join("\n ");
}

<textarea id="output" rows="5" cols="80"></textarea><br>
<button type="button" onclick =
"alert(getWords (document.getEl ementById('outp ut')))">
Test split()
</button>
Jul 23 '05 #4
Mick White wrote:
function getWords(formTe xtObject) {
return formTextObject. value.split(" ").join("\n ");
}

<textarea id="output" rows="5" cols="80"></textarea><br>
<button type="button" onclick =
"alert(getWords (document.getEl ementById('outp ut')))">
Test split()
</button>


That's not downwards compatible. Use this instead:

<form action="" onsubmit="retur n false">
<textarea name="output" rows="5" cols="80"></textarea><br>
<input
type="button"
value="Test split()"
onclick="alert( getWords(this.f orm.elements.ou tput))">
</form>

And don't forget to specify the script language for event handlers:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>
PointedEars
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16912
by: delerious | last post by:
I have a DIV that contains some links. I have an onmouseout event handler on the DIV, and I want it triggered only when the mouse leaves the DIV. Since there are Anchors in the DIV, onmouseout events will be generated when the mouse moves from one link to another, and those events will bubble up to the DIV. According to all the...
11
2006
by: Saqib Ali | last post by:
Please excuse me, this is a fairly involved question that will likely require you to save the file below to a file and open it in a browser. I use Mozilla 1.5, so the problem I describe below should be reproducible with that version at least. BACKGROUND: =========== When you open this page in your browser, you will see a 4 cell table....
6
1976
by: anon | last post by:
How *EXACTLY* does Smart Navigation work? (I would really really really like for this Smart Navigation to work in Mozilla.) The inner workings and the code is what I am looking for. Does it use JavaScript? If so, is there any code that someone can point to. And can the ASP.NET 2.0 team get this work in Mozilla....sort of targeting...
6
1549
by: Kor | last post by:
Hi, Does anybody understand why the technique described in http://www.macromedia.com/devnet/server_archive/articles/css_positioning_dynamic_repositioning.html doesnt work in Netscape 6/7 and Mozilla? I tried it out but to no avail. I am certainly not a (javascript) programmer / DOM expert but it seems to me it should work (see for example...
4
2150
by: Schraalhans Keukenmeester | last post by:
I have no clue why below code (found it somewhere and altered it a wee bit to my needs) will run without problem in both IE and Mozilla FireFox 1.0 but in the latter it takes up close to 100% cpu. It does check for type of browser, and indeed all works fine apart from that ridiculous amount of cpu taken. If you want to see if it does so in...
2
3479
by: mark4asp | last post by:
Why does this not work in Mozilla ? <http://homepage.ntlworld.com/mark.pawelek/code/animals.html> The optHabitat_change() event does not fire. What am I doing wrong here? PS: It should repopulate the 2nd combo based upon the value of the selected item in the first, just like it does in IE.
6
11050
by: Randell D. | last post by:
Folks, I've spent the past hour or so testing IFRAME with Mozilla 1.7.5 and not getting it to work - Then... I thought I'd try it in IE, and my code worked... Thus... is IFRAME an IE only feature? I use Mozilla most often and I am nearly sure that I have used a website that had an IFRAME like window... is there another method?
3
5683
by: LuTHieR | last post by:
Hi, I have an HTML document and would like to split it in pages for printing. It consist basically of many tables, and I would like that when I print it the output will be one table per physical page. Is it somehow possible? Thanks, LuTHieR
2
1447
by: naurus | last post by:
i have some JavaScript code that gets a variable from an input field, then parses it into a float. That all goes OK, but after that it gets weird: i put it variable.split("."); and FireBug gives me this error: timeSpanFull.split is not a function Here is a snippet of the code: timeSpanFull = parseFloat(fetchById('timeSpan').value); timeSpan...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.