---
title: "Problem med Script i Mozilla"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/109118-problem-med-script-i-mozilla"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "jazzil"
published: "2004-08-13T11:54:06.000Z"
updated: "2004-08-13T12:35:19.000Z"
replies: 2
views: 365
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/109118-problem-med-script-i-mozilla"
---

# Problem med Script i Mozilla

## #1 — jazzil, 2004-08-13T11:54Z

Tjena, jag har problem med ett script i mozilla firefox 9.x
Jag kan inte se något som gör att det skulle bli fel.

```
<html>
	<head>
		<title>
			Mekk
		</title>
	<script language="text/javascript" >
	var f = 1;
	function ViewBox()
		{
		var HejBox = document.getElementById('hej');
		var ion = (++f % 2 == 0); 
		HejBox.style.height = (ion ? '20' : '0'); 
		HejBox.style.visibility = (ion ? 'visible' : 'hidden'); 
		HejBox.style.width = (ion ? '100' : '0'); 
		HejBox.style.padding = (ion ? '0' : '0'); 
		}	
	</script>
	</head>
	<body>
		<form name="mekk" action="" method="post">
			<input id="Hello" type="checkbox"  OnClick="ViewBox();" />Hide<br />
			<input name="hej" Disabled="disabled" style="height: 0px; visibility: hidden; width: 0px; padding: 0px;" value="Hej" />
			Lite text
		</form>
	</body>
</html>
```

Och när jag kö den i IE så funkar den men IE vägra sätta 0 i height på min textbox.

Permalänk: https://www.webforum.nu/p/109118

## #2 — dectgap, 2004-08-13T12:09Z

*getElementById()* hämtar, som namnet antyder, ett element med ett visst id - inte ett element med ett visst namn.

Ändra därför

```
<input name="hej" [...]
```

till

```
<input id="hej" [...]
```

Sedan måste du, om värdet inte är 0, ange enhet för *width* och *height*:

```
	function ViewBox()
		{
		var HejBox = document.getElementById('hej');
		var ion = (++f % 2 == 0); 
		HejBox.style.height = (ion ? '20px' : '0'); 
		HejBox.style.visibility = (ion ? 'visible' : 'hidden'); 
		HejBox.style.width = (ion ? '100px' : '0'); 
		HejBox.style.padding = (ion ? '0' : '0'); 
		}
```

Dessutom får du ändra

```
<script language="text/javascript" >
```

till

```
<script type="text/javascript" >
```

Permalänk: https://www.webforum.nu/p/1409718

## #3 — jazzil, 2004-08-13T12:35Z

Tack! 

Jag som varit slarvig igen :r

Permalänk: https://www.webforum.nu/p/1409737

---

Tråden på webben: https://www.webforum.nu/amne/javascript/109118-problem-med-script-i-mozilla
