Jump to content

form.style.display = "none" ???

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
Hi,
I'm looking if there is an error in this js code;


//------------------------------------------------------------------

// HideIp

//..................................................................

// show or hide form

//------------------------------------------------------------------

function hideIp ( box, form ) {

     if (box.checked == true) {

          form.style.display = "";

     } else {

          form.style.display = "none";

     }

}


In an html page generated by a perl script there is some checkbox for different network(eth0, eth1, ...) when the checkbox is checked the 4 boxes composing the ip adresse must be show, and hidden when the checkbox is unchecked; but now I only have the boxes for my Ip adresses constantly obvious. Is there an error in this code? I don't find any and it don't work....
Thanks from advance!

#2
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
you propably want to ask your question here

#3
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
There is not an error in the code you showed us from what I can tell but you may be calling them wrong. Can you show us more of the code that you are using?

Try calling it based on the id:

document.getElementById('two').style.display = "none";


#4
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
Hello again,
I've tried this

document.getElementById('two').style.display = "none";

but it doesn't work...

So, here you have the html code in wich the precedent script will show or hide the Ip boxes.


<!DOCTYPE html

	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

<head>

<title>definition files creator</title>

<link rel="stylesheet" type="text/css" href="/ksedit.css" />

<script src="/ksedit.js" type="text/javascript"></script>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body onload="hideIp_onLoad(4)">


<form method="post" action="/cgi-bin/ksedit.pl" enctype="multipart/form-data" name="main_form">

<h1>

	Création de fichier de définition

</h1>

Selectionner la machine a editer: <select name="liste_serveurs" >

<option value="sli0153v">sli0153v</option>

<option value="sli0169v">sli0169v</option>

<option value="sli0170v">sli0170v</option>

</select><p />

<input type="submit" name="Charger" value="Charger" /><label>

	<input type="checkbox" name="edit" value="on" checked="checked" />edit

</label>

<p />

<hr />

<p />

<table>

	<tr>

		<td>Serveur</td>

		<td>:</td>

		<td><input type="text" name="HOSTNAME"  /></td>

	</tr>

	<tr>

		<td>Version</td>

		<td>:</td>

		<td><select name="OS_VERSION" >

<option value="4">4</option>

<option value="5">5</option>

<option value="5.1">5.1</option>

</select></td>

	</tr>

	<tr>

		<td>Modèle</td>

		<td>:</td>

		<td><select name="MODELE" >

<option value="DL380">DL380</option>

<option value="DL580">DL580</option>

<option value="X4150">X4150</option>

<option value="X4450">X4450</option>

</select></td>

	</tr>

	<tr>

		<td>Architecture</td>

		<td>:</td>

		<td><select name="ARCH" >

<option value="i386">i386</option>

<option value="x64">x64</option>

</select></td>

	</tr>

	<tr>

		<td>Nombre de disques</td>

		<td>:</td>

		<td><select name="NBDISK" >

<option value="1">1</option>

<option value="2">2</option>

</select></td>

	</tr>

	<tr>

		<td>eth0<label>

	<input type="checkbox" name="NIC0" value="on" onclick="hideIp(this, form0)" />

</label></td>

		<td>:</td>

		<td><div id="form0">

			<table>

				<td>IP:</td>

				<td><input type="text" name="IP_eth0_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth0_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth0_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth0_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

				<td>MASK:</td>

				<td><input type="text" name="MASK_eth0_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth0_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth0_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth0_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

			</table>

		</div></td>

	</tr>

	<tr>

		<td>eth1<label>

	<input type="checkbox" name="NIC1" value="on" onclick="hideIp(this, form1)" />

</label></td>

		<td>:</td>

		<td><div id="form1">

			<table>

				<td>IP:</td>

				<td><input type="text" name="IP_eth1_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth1_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth1_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth1_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

				<td>MASK:</td>

				<td><input type="text" name="MASK_eth1_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth1_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth1_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth1_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

			</table>

		</div></td>

	</tr>

	<tr>

		<td>eth2<label>

	<input type="checkbox" name="NIC2" value="on" onclick="hideIp(this, form2)" />

</label></td>

		<td>:</td>

		<td><div id="form2">

			<table>

				<td>IP:</td>

				<td><input type="text" name="IP_eth2_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth2_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth2_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth2_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

				<td>MASK:</td>

				<td><input type="text" name="MASK_eth2_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth2_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth2_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth2_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

			</table>

		</div></td>

	</tr>

	<tr>

		<td>eth3<label>

	<input type="checkbox" name="NIC3" value="on" onclick="hideIp(this, form3)" />

</label></td>

		<td>:</td>

		<td><div id="form3">

			<table>

				<td>IP:</td>

				<td><input type="text" name="IP_eth3_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth3_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth3_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="IP_eth3_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

				<td>MASK:</td>

				<td><input type="text" name="MASK_eth3_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth3_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth3_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="MASK_eth3_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

			</table>

		</div></td>

	</tr>

	<tr>

		<td>Gateway</td>

		<td>:</td>

		<td><input type="text" name="GATEWAY_1"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="GATEWAY_2"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="GATEWAY_3"  size="3" maxlength="3" onblur="verifIp(this)" />.<input type="text" name="GATEWAY_4"  size="3" maxlength="3" onblur="verifIp(this)" /></td>

	</tr>

	<tr>

		<td>IP principale</td>

		<td>:</td>

		<td><select name="NETDEV" >

<option value="eth0">eth0</option>

<option value="eth1">eth1</option>

<option value="eth2">eth2</option>

<option value="eth3">eth3</option>

</select></td>

	</tr>

	<tr>

		<td>Zone</td>

		<td>:</td>

		<td><select name="ZONE" >

<option value="zone-H">zone-H</option>

<option value="mcl">mcl</option>

</select></td>

	</tr>

	<tr>

		<td>bond0</td>

		<td>:</td>

		<td><label>

	<input type="checkbox" name="BOND0_eth0" value="on" />eth0

</label>

; <label>

	<input type="checkbox" name="BOND0_eth1" value="on" />eth1

</label>

; <label>

	<input type="checkbox" name="BOND0_eth2" value="on" />eth2

</label>

; <label>

	<input type="checkbox" name="BOND0_eth3" value="on" />eth3

</label></td>

	</tr>

	<tr>

		<td>bond1</td>

		<td>:</td>

		<td><label>

	<input type="checkbox" name="BOND1_eth0" value="on" />eth0

</label>

; <label>

	<input type="checkbox" name="BOND1_eth1" value="on" />eth1

</label>

; <label>

	<input type="checkbox" name="BOND1_eth2" value="on" />eth2

</label>

; <label>

	<input type="checkbox" name="BOND1_eth3" value="on" />eth3

</label></td>

	</tr>

</table>

<hr />

<p />

<input type="reset"  name=".reset" /><input type="submit" name="Actualiser" value="Actualiser" /><input type="submit" name="Enregistrer" value="Enregistrer" /><div><input type="hidden" name=".cgifields" value="BOND1_eth2"  /><input type="hidden" name=".cgifields" value="BOND0_eth2"  /><input type="hidden" name=".cgifields" value="NIC2"  /><input type="hidden" name=".cgifields" value="BOND0_eth1"  /><input type="hidden" name=".cgifields" value="BOND1_eth1"  /><input type="hidden" name=".cgifields" value="edit"  /><input type="hidden" name=".cgifields" value="NIC3"  /><input type="hidden" name=".cgifields" value="NIC0"  /><input type="hidden" name=".cgifields" value="BOND0_eth3"  /><input type="hidden" name=".cgifields" value="BOND0_eth0"  /><input type="hidden" name=".cgifields" value="BOND1_eth3"  /><input type="hidden" name=".cgifields" value="BOND1_eth0"  /><input type="hidden" name=".cgifields" value="NIC1"  /></div></form>

</body>

</html>



Edited by dimitry, 04 June 2009 - 12:31 AM.
just forget something I would say


#5
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
what BlaineSch suggested is using calling by id, you need to modify the function so it look like this :

function hideIp ( box, form ) {

     if (box.checked == true) {

          document.getElementById(form).style.display = "";

     } else {

             document.getElementById(form).style.display = "none";

     }

}

form here is the id of the element, it must be a string, so when you use the function pass the id as a string like this:

<input type="checkbox" name="NIC0" value="on" onclick="hideIp(this, 'form0')" />


yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#6
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
I've tried it with but it doesn't work.
Are you saying you suggest to remove "checked="checked"" in this line?
I'll try this... Now I'm wandering if my browser or just apache doesn't give me the permission to execute the js script.... I'll look if this is the cause...

#7
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
No, it doesn't seem to be the cause.... and it doesn't work...

I try, I ry, all the possibilities... if you have another idea it could be cool...

Thanks frome advance!

#8
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
it should be working perfectly, ive attached an example
<html>

<head>

<script type="text/javascript">

function check(checkbox,id)

{

if(checkbox.checked)

{

    document.getElementById(id).style.display="";

}else{

      document.getElementById(id).style.display="none";

    }

}

</script>

</head>

<body>

<input type="checkbox" id='chk1' onclick="check(this,'content')">

<div id='content'>content here blah blah blah</div>

</body>

</html>

Attached Files


yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#9
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
:001_huh:
It should work, I'm ok with amrosama...
I've put a new function in the
function alert_message

{

     var msg= "The box is checked => Done!";

     alert(msg);

}

and I call the function with
alert_message;

This is just to verify if this part is really executed...

#10
dimitry

dimitry

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
Hello,
it's ok, it works, it should be the browser version who was a little bit old or something like that; my script wasn't executed... I've test it on the servers where I must apply it; it's ok.
Thanks for your help!:cool: