Page 1 of 1

JS doesn't work with my PHP file

Posted: Sat Dec 09, 2006 1:53 pm
by Betty_S
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I wrote a simple js function:

Code: Select all

echo "<script type=\"text/javascript\">";
echo "function alertBtn()";
echo"{alert(document.getElementById(\"btn\").id)}";
echo "</script>";
It refuses to fire, did I miss some important point or should I just recheck my code?

Additionally, is there a special php command for conetcting the php file to a js file or should I just add "<script src=…></script>"?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Dec 09, 2006 5:53 pm
by ok
Please post the HTML source which comes with the JS function.

If you want to print a dynamic JS file, you can use it in the src attribute in the script tag:

Code: Select all

<script src="http://www.example.com/js.php" type="text/javascript"></script>
But, if you want to communicate with PHP through JS, you need AJAX: http://developer.mozilla.org/en/docs/AJAX

Posted: Sat Dec 09, 2006 8:41 pm
by califdon
I'm confused by what you asked. The snippet you showed merely sends that javascript code to the browser as part of the html. If it's not working, it's because you aren't calling it properly from somewhere else in the html. Where is the place that calls that function? That's the part that is failing.

thats the code

Posted: Sun Dec 10, 2006 1:02 am
by Betty_S
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

echo "<script language=\"JavaScript\" type=\"text/javascript\">";
			echo "function filter(){alert(document.all(\"hdn\").value)}";
			echo "function filterx(){alert(document.getElementById(\"btn\"))";
			echo "</script>";
			echo "<input type=\"hidden\" id=\"hdn\" name=\"hdn\" value=".$id." />";
			echo "<input type=\"button\" id=\"btn\" name=\"btn\"  value=\"&#1505;&#1504;&#1503;\" onclick=\"filterx()\"/> ";

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Dec 10, 2006 10:58 am
by neel_basu
Betty_S wrote:echo "<script language="JavaScript" type="text/javascript">";
echo "function filter(){alert(document.all("hdn").value)}";
echo "function filterx(){alert(document.getElementById("btn"))";
echo "</script>";
echo "<input type="hidden" id="hdn" name="hdn" value=".$id." />";
echo "<input type="button" id="btn" name="btn" value="סנן" onclick="filterx()"/> ";
After The Red Marked ) There Should Be A }