Thread: syntax question

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    12
    Rep Power
    0

    syntax question


    I am trying to get a confirmation box(javascript) displayed when a user clicks on a link to delete one of the database entries in my database.

    I have found the following code that when clicked will offer an ok or cancel alert box and continue to the correct page if pressed 'ok' otherwise if pressed 'cancel' the user will remain on the same page. This is exactly what I am looking for as the link to the next page on my website is the page that will delete the database entry.

    <a href="http://www.codetoad.com" onclick="javascript:return confirm('Are you sure you want to return to the home page ?')"><BR>
    Click here to return home</a>

    Unfortunately this has got to occur in a whole bunch of jsp code that I am using to display the available database records that could be deleted if they wanted, and I dont know how to add this line of javascript into the jsp line of code?

    This is the original line of jsp code without the javascript:

    out.println("<tr><td>" + username
    + "</td><td>" + thesestitle
    + "</td><td><a href=view2.jsp?memberID=" + ID + " >view</a></td><td><a href=edit.jsp?memberID="
    + ID + ">edit</a></td><td><a href=delete.jsp?memberID=" + ID + " >delete</a></td></tr>");


    This is my attempt but it brought up errors:

    out.println("<tr><td>" + username+ "</td><td>" + thesestitle+ "</td><td><a href=view2.jsp?memberID=" + ID + " >view</a></td><td><a href=edit.jsp?memberID="
    + ID + ">edit</a></td><td><a href=delete.jsp?memberID=" + ID + "%> onclick="javascript:return confirm('Are you sure you want to delete this entry?')"<% ><BR>delete</a></td></tr>");

    I am really stuck on this, any help much appreciated
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3887

    Re: syntax question


    You can do it all in your out.println() statement:
    Code:
    out.println("<tr><td>" + username+ "</td><td>" + thesestitle+ "</td><td><a href=view2.jsp?memberID=" + ID + " >view</a></td><td><a href=edit.jsp?memberID="
    + ID + ">edit</a></td><td><a href=delete.jsp?memberID=" + ID + " onclick=\"javascript:return confirm('Are you sure you want to delete this entry?')\" ><BR>delete</a></td></tr>");
    ~ishnid

    Edit: For some reason it seems to display a space between 'java' and 'script' that I didn't put there.
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14

    Re: Re: syntax question


    Originally posted by ishnid
    Edit: For some reason it seems to display a space between 'java' and 'script' that I didn't put there.
    VBulletin throws a space in there for security reasons. Always be sure to look for spaces when you copy someones code from here.
    -james
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3887

    Re: Re: Re: syntax question


    Originally posted by bricker42
    VBulletin throws a space in there for security reasons. Always be sure to look for spaces when you copy someones code from here.
    Does that just happen in the [code] tags? It seems to display OK in bmcnicoll's original post.
    ~ishnid
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Yeah, I think just code and php tags when in a href. I have also noticed that php tags remove backslashes sometimes. That is why, even though i love the color coding, I never use php tags.
    -------------
    original
    -------------
    This is a \test
    javascript
    <a href="javascript:something()">pfft</a>
    Code:
    This is a \test
    javascript
    <a href="javascript:something()">pfft</a>
    PHP Code:
    this is a \test
    javascript
    <a href="javascript:something()">pfft</a
    EDIT: Looks like it is adding the space in javascript in an anchor tag no matter where I put it. None of the "javascript"s I printed have any spaces by me.
    Last edited by Nemi; March 31st, 2003 at 10:24 AM.

IMN logo majestic logo threadwatch logo seochat tools logo