LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   combining JavaScript and PHP (https://www.linuxquestions.org/questions/programming-9/combining-javascript-and-php-458926/)

mohtasham1983 06-27-2006 05:58 PM

combining JavaScript and PHP
 
I have decleared a function by Javascript before body of my page:
Code:

<script type="text/javascript">
<!-- Hide the script
function warn_on_submit()
{
        var msg = "Are you sure, Dude????";
        if (confirm(msg))
                location.replace('update.php');
        else
                location.replace('java.php');>";
}
// end hiding -->
</script>

I have a form inside my PHP and I want to call my JavaScript function when onClick event is occured:
PHP Code:

print "<form method='POST' action='update.php' name='form1'>";
print 
"<input type='hidden' name='unique_id' value='{$unique_id}'>";
print 
"<input type='submit' value='update' onClick='warn_on_submit();'>";
print 
"</form>"

But when I submit the form I don't see any message asking for confirmation.

I am quite new to Javascript so excuse me if it was a stupid question

dugas 06-27-2006 09:49 PM

It is that extra >"; you have in your else statement.

mohtasham1983 06-28-2006 07:48 AM

thank you very much. I should have been more careful about that.
my new problem is that when I press ok or cancel i got to update.php and cancel button doesn't do anything in this page

Spudley 06-28-2006 08:38 AM

If you're using Firefox, you can use its built-in Javascript console to help you spot things like this.

Assuming you've got it set up the way I have, you should find the Javascript console option in the tools menu; any JS errors will show up in there, with their line numbers and error message. It would probably have helped you a lot in this case.

Other browsers also have features that do the same thing, but Firefox is the best for debugging JS, IMHO.

mohtasham1983 06-28-2006 11:02 AM

Here is the error which is written in Javascript console of Firefox:

Error: Expected ':' but found '='. Declaration dropped.
Source File: http://mohi/change.php
Line: 0

Everything seems correct :(

mohtasham1983 07-03-2006 05:10 PM

I run this simple html file which contains javascript. but it doesn't show anything on my firefox webbrowser.even JavaScript console doesn't show anything

Quote:

<HTML>
<HEAD>
</HEAD>
<script language="javascript">
function versio()
{
document.write('<b>Your browser supports JavaScript ' + js_version + '</b>')
}
</script>
<!-- start the frame animation when the document is fully loaded -->
<BODY onLoad="versio();" >

</BODY>
</HTML>

spooon 07-03-2006 07:01 PM

Quote:

Originally Posted by mohtasham1983
I run this simple html file which contains javascript. but it doesn't show anything on my firefox webbrowser.even JavaScript console doesn't show anything

Error: js_version is not defined


All times are GMT -5. The time now is 05:50 PM.