HTML Old School
Passing variables to PHP and JS scripts
Some advanced techniques in passing variables to PHP and JavaScript scripts.
Input text variables <input type="text">
PHP script uses $_GET, $_POST or $_REQUEST arrays.
If you want to explode these arrays use for example extract($_POST);
Example with PHP extract : 40passvars_php_extract.php
JS script uses: var x=document.forms[0].firstname.value;
Pass variable and open in new browser's window: 41passvars_js_newwindow.html
Textarea <textarea></textarea>
Into textarea we can insert HTML tags and preview document in new window.
Example with HTML elemnts in textarea: 42passvars_js_textarea.html
Select multiple
When you put multiple in <select name="naselje" size="9" multiple> then variable naselje is array.
Javascript collect array from <select name="naselje" size="9" multiple>: 44passvars_js_select_multiple.html
PHP also collect array from <select name="naselje[]" size="9" multiple>: 44passvars_php_select_multiple.php
File <input type="file">
PHP get file name from the <input type="file" name="pics"> via $_FILES array.
Example with $_FILES['pics']['name']: 08file_multiple.html
PHP script: 08file_script.php
JS get file name with: var x=document.forms[0].fajl.value;
Example: 43passvars_js_file.html
:::... Tricks ...:::
1. If you want open new window when submit button is clicked use:
<input type="Submit" value="Send data" onClick="new_window()">
At the same time will be form submitted and new window opened: 45trick_js_thankswindow.html
2. To focus element - put cursor inside it after page load use:
<script type="text/javascript" language="JavaScript">
document.forms[0].elements[0].focus();
</script>
Example: 46trick_js_focus.html