LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-27-2006, 06:58 PM   #1
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Rep: Reputation: 30
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
 
Old 06-27-2006, 10:49 PM   #2
dugas
Member
 
Registered: Jul 2004
Location: louisiana
Distribution: fedora 4/kubuntu
Posts: 116

Rep: Reputation: 15
It is that extra >"; you have in your else statement.
 
Old 06-28-2006, 08:48 AM   #3
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
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
 
Old 06-28-2006, 09:38 AM   #4
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
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.
 
Old 06-28-2006, 12:02 PM   #5
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
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
 
Old 07-03-2006, 06:10 PM   #6
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
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>

Last edited by mohtasham1983; 07-03-2006 at 06:12 PM.
 
Old 07-03-2006, 08:01 PM   #7
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
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
 
  


Reply

Tags
javascript, php


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP,JAVASCRIPT and CheckBox aznita Programming 2 06-17-2005 05:33 AM
Can I use PHP variables in javascript? nickiv Programming 1 06-07-2005 06:41 AM
JavaScript & PHP Gerardoj Programming 1 06-11-2004 01:02 AM
PHP and JavaScript Gerardoj Programming 4 04-22-2004 03:02 PM
PHP and or Javascript Can they be used the same way? ElementNine Programming 1 03-05-2004 09:22 AM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration