Hi my question is about how a problem was solved… a friend has html a code like:
<div id="result">
<script type="text/javascript">
function selectColor(value){
return "#319336";
}
</script>
</div>
and with a jQuery .load() call in result calls a PHP file with a function that sends a JavaScript function like this
<?php
function returnFuntion(){
return '<script type="text/javascript">
function selectColor(value){
switch(value){
case "a":
return "#000000";
break;
case "b":
return "#FFFFFF";
break;
default:
return "#319336";
}
}</script>';
}
?>
I don’t know how this is working, but works in all browsers, my friend says “it works don’t worry”. What happens? Why JavaScript recognizes the new code and not the old? Is that a correct way to do it? The original problem was the JavaScript function return must change with MySQL values obtained from PHP.
These are function declarations and the parser always reads these declarations before any code is read.
So the first function is simply overridden when the second is defined
FIDDLE