• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Java+PHP] Select options and onChange.

xFalcon

New Member
Joined
Dec 2, 2011
Messages
33
Reaction score
1
Well I'm trying to make a script for my website that show a text when player choose an option on a select tag.
Here is what I did but cant get it working >.<
PHP:
<?php
	echo '<table>
			<tr>
				<td>	<center><b>Select your region:</b></center>	</td>
				<td>	<select name="reg" id="reg" onChange="alter();">
							<option value="">-----------</option>
							<option value="EU">EUROPE</option>
							<option value="CH">CHINA</option>
						</select>
				</td>
			</tr>
		</table>
		<br />
		<div id="CH" style="display:none">hi china</div><br />
		<div id="EU" style="display:none">hi europe</div>';		
?>

Here is my javascript function..
Code:
function alter() {							
if(document.getElementById('reg').value == "CH") {document.getElementById('CH').display = ""; document.getElementById('EU').display = "none";};
if(document.getElementById('reg').value == "EU") {document.getElementById('EU').display = ""; document.getElementById('CH').display = "none";};
}
 
PHP:
<?php
echo '<table>
            <tr>
                <td>    <center><b>Select your region:</b></center>    </td>
                <td>    <select name="reg" id="reg" onchange="javascript:updateL();">
                            <option value="">-----------</option>
                            <option value="EU">EUROPE</option>
                            <option value="CH">CHINA</option>
                        </select>
                </td>
            </tr>
        </table>
        <br />
        <div id="CH" style="display:none">hi china</div>
        <div id="EU" style="display:none">hi europe</div>';
?>

PHP:
function updateL() {    
    var valL = document.getElementById('reg').options[document.getElementById('reg').selectedIndex].value;
    
    if(valL == "CH") {document.getElementById('CH').style.display = "";document.getElementById('EU').style.display = "none";}
    if(valL == "EU") {document.getElementById('EU').style.display = "";document.getElementById('CH').style.display = "none";}
}
 
Yesterday I could get it working thanks anyways :] I'm having this other problem though.. Here is my code:

PHP:
if(!isset($_REQUEST['action']) or ($_REQUEST['action'] != 'final')) {
	echo '<form action="?page=form&action=final" method="post" name="form">
		<table cellspacing=15 width="80%">
			<tr>
				<td>	<center><b>Select your Region:</b></center>	</td>
				<td>	<select name="reg" id="reg" onChange="alterreg();" style="width:150px">
							<option></option>
							<option value="EU">Europe</option>
							<option value="CH">China</option>
						</select></center>
				</td>				
			</tr>
		</table>
		<input type="submit" id="enter" value="Process" style="display:none;width:150px"/>
		</form>
}
else {
	if(empty($_POST['reg'])) echo 'fill reg';
	else echo $_POST['reg'];
}

I want when player select CH or EU and click on buttom 'Process' I can get the value with $_POST['reg'].. but I'm always getting 'fill reg'.. like if it was always empty >.<
 
Back
Top