Skip to content

Instantly share code, notes, and snippets.

@martin-mok
Created August 14, 2019 01:24
Show Gist options
  • Save martin-mok/056db49b2cadcfa3a40997414ded9a66 to your computer and use it in GitHub Desktop.
Save martin-mok/056db49b2cadcfa3a40997414ded9a66 to your computer and use it in GitHub Desktop.
Form_post_testing
<?php
echo nl2br(__LINE__ . "\n" . __FILE__ . " " . __DIR__ . "\n" . __NAMESPACE__ . strval(1+2) . "\n" . "abc\n");
?>
<script>
function submit_action(action, edit_id){
document.getElementById('action').value=action;
document.getElementById('edit_id').value=edit_id;
if(action=="bad_weather"){
/*
if(document.getElementById('bad_weather').selectedIndex==0){
document.getElementById("Enable").selected = true;
}else{
document.getElementById("Disable").selected = true;
}
*/
document.getElementById('form').submit();
}else
document.getElementById('form').submit();
}
</script>
<form id='form' action='#' method='post'>
<input type="hidden" id="action" name="action" value="">
<input type="hidden" id="edit_id" name="edit_id" value="-1">
Bad Weather:
<select id='bad_weather' name='bad_weather' onchange="submit_action('bad_weather', -1)">
<option value="">Select:</option>
<option id="Enable" value="Enable">Enable</option>
<option id="Disable" value="Disable">Disable</option>
</select>
</form>
<?php
if(isset($_POST['action']) && $_POST['action']=="bad_weather"){
echo "You have selected :" . $_POST['bad_weather']; // Displaying Selected Value
}
?>
<form action="#" method="post">
<select name="Color">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Pink">Pink</option>
<option value="Yellow">Yellow</option>
<input type="radio" name="radio" value="Radio 1" checked>Radio 1
<input type="radio" name="radio" value="Radio 2">Radio 2
<input type="radio" name="radio" value="Radio 3">Radio 3
</select>
<input type="submit" name="submit" value="Get Selected Values" />
</form>
<?php
//https://www.formget.com/php-select-option-and-php-radio-button/
if(isset($_POST['submit'])){
echo "You have selected :".$_POST['Color'].' Color and '.$_POST['radio']; // Displaying Selected Value
}
?>
<select onchange="jsFunction()" id="select-test">
<option value="" disabled selected style="display:none;">Label</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<script>
function jsFunction(){
document.getElementById("testing").innerHTML = document.getElementById("select-test").value;
}
</script>
<div id='testing'>
testing screen
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment