Hi. I want to use javascript in php for validation. The task I want to do is to give the warning message to user if the user tries to delete the record of the mysql database. And if he wants to delete then he will be forwarded to deletion of record's page otherwise not. And I have used one dynamic link along with record. So, how can I put the validation using javascript? Please help me. It's very urgent. Thanks in advance.
From the server side, you have to treat javascript just like HTML. It is nothing complex, you may probably create part of javascript dymanically just like you will dynamically create HTML. Your PHP code will look like the example below. Basically you have to be clear about the fundamentals .. what is javascript / where it works and so on. Do not get confused with a server side technology and client side. Clear fundamentals and clear logic is what you need. echo "<script language = 'javascript'> js goes here.. //call function with a dynamic ID function abcd(".$id."); ............. </script>"; Code (markup):
try this one: <a href="javascript:if(confirm ('Are you sure you want to delete the record?'))window.location.href='DELETE_RECRORD_PAGE.URL';">Delete</a>
Or this so the link would still work even if Javascript is disabled. <a href="delete.php?id=2" onclick="return confirm('Are you sure?');">Delete</a> HTML:
I tried like this echo '<a href=dropdb.php?name='.$row->Database.' onClick="return confirm("Are you sure?");">Delete</a> but it didn't worked. What should be the problem?
Try: echo '<a href="dropdb.php?name='.$row->Database.'" onClick="return confirm(\'Are you sure?\');">Delete</a>'; PHP: With the appropriate quotes.
nico, you're always on top of things around here on the php boards either that or im just slow. haha.