Javascript in PHP????

Discussion in 'PHP' started by computerzworld, Jun 6, 2007.

  1. #1
    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.
     
    computerzworld, Jun 6, 2007 IP
  2. alemcherry

    alemcherry Guest

    Best Answers:
    0
    #2
    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):
     
    alemcherry, Jun 6, 2007 IP
  3. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #3
    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>
     
    YIAM, Jun 6, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    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:
     
    nico_swd, Jun 6, 2007 IP
  5. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    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?
     
    computerzworld, Jun 6, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Try:
    
    echo '<a href="dropdb.php?name='.$row->Database.'" onClick="return confirm(\'Are you sure?\');">Delete</a>';
    
    PHP:
    With the appropriate quotes.
     
    nico_swd, Jun 6, 2007 IP
    computerzworld likes this.
  7. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #7
    It worked...........:)
    thanks!!!!!!!!!!!!
     
    computerzworld, Jun 6, 2007 IP
  8. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #8
    nico, you're always on top of things around here on the php boards :) either that or im just slow. haha.
     
    ansi, Jun 7, 2007 IP