PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi there,
I've an issue with sending a value from within a PHP function with onChange (javaScript)
My function does very well, exept for submitting the appropriate value. Virtually nothing happens
So here's the function:
Actually this function displays a selectbox wich generates a formatted output from a datetime mysql data type field.
// displays a selectbox with the db-record and appropriate labeling..
function database_select($tbl_value, $select_name, $label) {
global $DB_WE;
$menu = "e;<label for=\"e;"e;.$select_name."e;\"e;>"e;.$label."e;</label>\n"e;;
// here is the problem:
$menu .= "e;<select name=\"e;"e;.$select_name."e;\"e; onchange=\"e;document.location.href='"e;.$_SERVERї"e;PHP_SELF"e;]."e;?ViewYear="e; ?WHAT DO I HAV TO PUT IN HERE? "e;\"e;>\n"e;;
//end problem
$DB_WE->query("e;SELECT DATE_FORMAT(DateOrder,'%Y') AS DateOrder FROM "e;.SHOP_TABLE . "e; GROUP BY DateOrder"e;);
while ($DB_WE->next_record()) {
$menu .= "e; <option value=\"e;"e;. $DB_WE->f("e;DateOrder"e;)."e;\"e;"e;;
$menu .= (isset($_REQUESTї$select_name]) && $DB_WE->f("e;DateOrder"e;) == $_REQUESTї$select_name]) ? "e; selected=\"e;selected\"e;"e; : "e;"e;;
$menu .= "e;>"e; . $DB_WE->f("e;DateOrder"e;) . "e;\n"e;;
}
$menu .= "e;</select>\n"e;;
return $menu;
}
Just noticed you've got escaped quotes in one place, and no escaping in another (the = sign), so that'll cause problems in the HTML parsing and the JS parsing. This problem just seems to be that you've gotten really mixed up putting the PHP and JS together and made a few syntax errors.
With inline JS, use single quotes instead (escaping required parsed by PHP rather than the browser) and remember to quote the whole inline JS:
I think that should work for you. escaping quotes when going between php and javascript is always a pain.
Thank you very much. Yeah it is a pain
Well, now I havn't got any errors, but apparently the javaScript - variables were not extracted accurately. Look at the chunk of source-code (..you know- view source...)