me_the_seven me_the_seven -4 years ago 54
PHP Question

JS methods does not load in onload method

I have a

HTML
file, with some
Script
inside.
I bring all
functions
in one
Script
Tag.
Now I want to use these methods in
onload
and
onclick
events.
Here is this HTML file with all scripts :

<!DOCTYPE html>

<html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js">

</script>
<script src="../configwireless.php">

</script>
<title>configuration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
.center {
margin: auto;
width: 40%;
border: 3px solid #73AD21;
padding: 10px;
text-align: center;
margin-left: auto;
margin-right: auto;
background : url(wall5.jpg) center no-repeat;
}
@font-face {
font-family: myFont;
src: url(fonts/Raleway-Medium.otf);
src: url(fonts/Raleway-Medium.ttf);
src: url(fonts/Raleway-Medium.woff);

}
body {
font-family:myFont;
background : url(wall5.jpg) center;
height: 100%;
font-family:myFont;
background-position: center;
background-repeat: repeat;
background-size: cover;
width: 100%;
}
lable {
font-family:myFont;
}
form{
font-family: myFont;


}
input {
text-align: center;
}


</style>

</head>
<body>
<form name="general" action="" id="general" class="center" method="post">

<div id="wirelessmodediv">
<label>Wireless Mode</label>
<select name="wirelessmode" id="wirelessmode"
onclick="checkGeneralWirelessMode()">
<option value="ap">AP</option>
<option value="xxx">Client</option>
<option value="xxx">Client Bridge(Routed)</option>
<option value="xxx">Adhoc</option>
<option value="xxx">WDS Station</option>
<option value="xxx">WDS AP</option>
</select> <br>
</div>
<div id="networkmodediv">
<label>Wireless Network Mode</label>
<select name="wirelessNetworkMode" id="wirelessNetworkMode">
<option value="disabled">Disable</option>
<option value="mixed">Mixed</option>
<option value="a-only">A-Only</option>
<option value="na-only">NA-Mixed</option>
<option value="n5-only">N-Only(5 GHz)</option>
</select> <br>
</div>

<div id="channelwidthdiv" >
<label> Channel Width </label>

<select id="channelWidth" name="channelWidth">
<option value="20">Full</option>
<option value="40">Wide </option>
<option value="2040">Dynamic </option>
<option value="10">Half (10 MHz)</option>
<option value="5">Quarter(5 MHz)</option>
</select> <br>
</div>
<div id="countrydiv">
<label>Country</label>
<select id="country" name="country"
onchange="fillWirelessChannel();"
onload="fillWirelessChannel();"
onclick="fillWirelessChannel();">
<option value="china" >China</option>
<option value="japan" >japan</option>
</select>
</div>
<br>
<div id="wirelesschannel">
<label>Wireless Channel</label>

<select id="wirelessChannel" name="wirelessChannel">

</select>
</div>
<br>

<div id="extentionchanneldiv">
<label> Extention Channel </label>

<select id="extentionChannel" name="extentionChannel">
<option value="auto">auto</option>
<option value="lower">lower</option>
<option value="upper">upper</option>
</select>
</div>
<br>
<div id="linkname" >
<label>Wireless Link Name</label>

<input type="text" name="ssid" id="ssid" /><br>
</div>

<div id="ssidbroadcast" >
<label>Wireless SSID Broadcast</label>

<input type="radio" name="broadcaststatus" id="enablebroadcaststatus"
value="0"> Enable
<input type="radio" name="broadcaststatus" id="disablebroadcaststatus" value="1" > Disable <br>
</div>
<div id="gatewaydiv" >
<label>Default GW Mode</label>

<input type="radio" name="gateway" id="gateway" value="1" onclick="checkDefaultGateway()"> Auto (DHCP)
<input type="radio" name="gateway" id="gateway" value="0" onclick="checkDefaultGateway()"> Manual <br>
</div>


<div id="gatewayipdiv" >
<label>Gateway</label>
<input type="text" name="gatewayip" id="gatewayip" ><br>
</div>


<label>Advanced Setting</label>

<input type="checkbox" name="advancecheck" id="advancecheck"
onchange="advancecheckChanged()"
onload="advancecheckChanged()"/><br>



<div id="advanceddiv" style="display:none;">

<label>Super Channel</label>

<input type="radio" name="supperchannel" value="ebable"> Enable
<input type="radio" name="supperchannel" value="disable"> Disable <br>
<label>TX Power</label>

<input type="text" name="txpower" id="txpower"><br>
<label>Antenna Gain</label>

<input type="text" name="antennagain" id="antennagain"><br>

<label>Noise Immunity</label>

<input type="radio" name="noise" id="enablenoise" value="1"> Enable
<input type="radio" name="noise" id="disablenoise" value="0"> Disable <br>
<label> Protection Mode </label>

<select id="protection">
<option value="None">one</option>
<option value="CTS">CTS</option>
<option value="RTS/CTS">RTS/CTS</option>
</select> <br>
<label>RTS Threshold</label>

<input type="text" name="rts" id="rts"> <br>
<label>Short Preamble</label>

<input type="radio" name="preamble" id="enablepreamble" value="ebable"> Enable
<input type="radio" name="preamble" id="disablepreamble" value="disable"> Disable <br>
<label>Short GI</label>

<input type="radio" name="gi" id="enablegi" value="1"> Enable
<input type="radio" name="gi" id="disablegi" value="0"> Disable <br>
<label>TX Antenna Chains</label>

<select id="txantennachains">
<option value="1">1</option>
<option value="3">1+2</option>

</select><br>
<label>RX Antenna Chains</label>

<select id="rxantennachains">
<option value="1">1</option>
<option value="3">1+2</option>

</select><br>
<label>Beacon Interval</label>
<input type="text" name="interval" id="interval"><br>

<label>DTIM Interval</label>
<input type="text" name="dtiminterval" id="dtiminterval"><br>
<label>AP Isolation</label>
<input type="radio" name="isolation" id="enableisolation" value="1"> Enable
<input type="radio" name="isolation" id="disableisolation" value="0"> Disable <br>

<label>Sensitivity Range (ACK Timing)</label>

<input type="text" name="sensitiverange" id="sensitiverange"><br>
<label>Max Associated Clients</label>

<input type="text" name="maxassociate" id="maxassociate"><br>
<label>Network Configuration</label>
<input type="radio" name="configuration" id="enableconfiguration" value="0"
onload="checkBridgeMode()"
onclick="checkBridgeMode()"
onchange="checkBridgeMode()"> Unbridge
<input type="radio" name="configuration" id="disableconfiguration" value="1"
onload="checkBridgeMode()"
onclick="checkBridgeMode()"
onchange="checkBridgeMode()"> Bridge<br>

<div id="multicastdiv">
<label>Multicast forwarding</label>

<input type="radio" name="multicast" id="enablemulticast" value="1"> Enable
<input type="radio" name="multicast" id="disablemulticast" value="0"> Disable <br>

<label>Masquerade / NAT</label>

<input type="radio" name="masquerade" id="enablemasquerade" value="1"> Enable
<input type="radio" name="masquerade" id="disablemasquerade" value="0"> Disable <br>

<label>Net Isolation</label>

<input type="radio" name="netisolation" id="enablenetisolation" value="1"> Enable
<input type="radio" name="netisolation" id="disablenetisolation" value="0"> Disable <br>

<label>Forced DNS Redirection</label>


<input type="radio" name="forcedns" id="enableforcedns" value="1"
onload="Checkradiobutton()" onclick="Checkradiobutton()" > Enable
<input type="radio" name="forcedns" id="disableforcedns" value="0"
onload="Checkradiobutton()" onclick="Checkradiobutton()"> Disable <br>


<label>Optional DNS Target</label>

<input type="text" name="optionaldns" id="optionaldns"><br>
<label>IP Address</label>

<input type="text" name="ipaddress" id="ipaddress"><br>
</div>
</div>


<div id="subnetmaskdiv" style="display:none;">
<label>Subnet Mask</label>
<input type="text" name="subnetmask" id="subnetmask"><br>
</div>

<input type="submit" name="apply" id="apply" value="Apply"/>
</form>

<script type="text/javascript">

function checkGeneralWirelessMode() {

if ((document.getElementById('wirelessmode').value == "ap") ||
(document.getElementById('wirelessmode').value == "infra") ||
(document.getElementById('wirelessmode').value == "wdsap"))
{

document.getElementById("channelwidthdiv").style.display = 'block';
document.getElementById("countrydiv").style.display = 'block';
document.getElementById("extentionchanneldiv").style.display = 'block';
document.getElementById("wirelesschannel").style.display = 'block';
document.getElementById("linkname").style.display = 'block';
document.getElementById("ssidbroadcast").style.display = 'block';
document.getElementById("networkmodediv").style.display = 'block';

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

} else if (document.getElementById('wirelessmode').value == "wet") {

document.getElementById("networkmodediv").style.display = 'block';
document.getElementById("gatewayipdiv").style.display = 'block';
document.getElementById("linkname").style.display = 'block';
document.getElementById("gatewaydiv").style.display = 'block';

document.getElementById("extentionchanneldiv").style.display = 'none';
document.getElementById("channelwidthdiv").style.display = 'none';
document.getElementById("countrydiv").style.display = 'none';
document.getElementById("wirelesschannel").style.display = 'none';
document.getElementById("ssidbroadcast").style.display = 'none';

} else if (document.getElementById('wirelessmode').value == "sta" ||
document.getElementById('wirelessmode').value == "wdssta") {

document.getElementById("channelwidthdiv").style.display = 'block';
document.getElementById("linkname").style.display = 'block';
document.getElementById("networkmodediv").style.display = 'block';

document.getElementById("extentionchanneldiv").style.display = 'none';
document.getElementById("gatewayipdiv").style.display = 'none';
document.getElementById("gatewaydiv").style.display = 'none';
document.getElementById("countrydiv").style.display = 'none';
document.getElementById("wirelesschannel").style.display = 'none';
document.getElementById("ssidbroadcast").style.display = 'none';
}

}

function advancecheckChanged() {
if (document.getElementById('advancecheck').checked &&
document.getElementById('enableforcedns').checked) {

document.getElementById("advanceddiv").style.display = 'block';
document.getElementById("subnetmaskdiv").style.display = 'block';
} else
document.getElementById("advanceddiv").style.display = 'none';
document.getElementById("subnetmaskdiv").style.display = 'none';

}
function fillWirelessChannel() {
var index;
var selectTag = document.getElementById('wirelessChannel');
selectTag.options.length = 0;
var auto = document.createElement("option");
auto.value = 'auto';
auto.innerHTML = 'auto';
selectTag.appendChild(auto);
// console.log(document.getElementById('country').value);

if (document.getElementById('country').value == "iran") {
for (index = 4920; index <= 5825; index += 5) {
var opt = document.createElement("option");
opt.value = index;
opt.innerHTML = index;
selectTag.appendChild(opt);
}
} else if (document.getElementById('country').value == "japan") {
for (index = 4920; index <= 6075; index += 5) {
var otherOpt = document.createElement("option");
otherOpt.value = index;
otherOpt.innerHTML = index;
selectTag.appendChild(otherOpt);
}
}
}

function checkDefaultGateway() {
if (document.getElementById('gateway').checked) {
document.getElementById("gatewayipdiv").style.display = 'none';
} else
document.getElementById("gatewayipdiv").style.display = 'block';

}

function checkBridgeMode() {
if (document.getElementById('enableconfiguration').checked) {
document.getElementById("multicastdiv").style.display = 'block';
} else
document.getElementById("multicastdiv").style.display = 'none';
}

function Checkradiobutton() {
if (document.getElementById('enableforcedns').checked) {
document.getElementById("subnetmaskdiv").style.display = 'block';
} else
document.getElementById("subnetmaskdiv").style.display = 'none';
}
</script>
</body>

</html>


I can call methods in
onclick
event via using
onclick
method in every tag I want use a specific method.
But I want to try all methods in
onload
.
I tried
onload="functionName;"
in tags, but no effect.
I used
window.onload="functionName";
in end of the script tags, but no effect.
I just could use

window.onload=function somefuntion() {


in function declaration and in worked.
But just for one method I can do that and when I do in this way the
onclick
method does not work.
How can I use these methods in
onload
and in
onclick
both? in my satisfied tags?

Answer Source

Maybe just:

window.addEventListener("load", function(event){
  someFunc1();
  someFunc2();
},false);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download