Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very small javascript is not running on php page

Tags:

javascript

I have javascript working in similar pages, but for some reason this one page does not load the JS at all. It's not that the code isn't working (it's just a few lines), but on my code debugger (using chromes "inspect element" feature) the javacsript isn't even registered as a script. I suppose there is some issue in where I am placing it.

I have a header included at the top, then put the script immediately, as follows:

<? 
/* Include Files *********************/
require_once("common/header.php");
/*************************************/
?>

<script language="JavaScript" type="text/javascript">
    ClearSearch(){
        document.getElementById('search_q').value = '';
    }
</script>

Lower in the page, I have a button that calls this function onclick:

<input type="submit" name="submit_search" value="Show All" onclick="javascript:ClearSearch();">

When I click the button, not only is the text box not cleared, but the javascript doesn't seem to run at all. It's as if the script isn't being detected. Any ideas?

like image 509
Anthony Avatar asked Dec 22 '22 13:12

Anthony


1 Answers

Missing function before your function declaration.

function ClearSearch(){
    document.getElementById('search_q').value = '';
}
like image 119
Niklas Avatar answered Jan 17 '23 02:01

Niklas