We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,167 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to prompt a confirm dialog box using links not buttons

hi there,

is there a way to prompt user dialog box using links not buttons??

4
Contributors
16
Replies
4 Days
Discussion Span
6 Months Ago
Last Updated
19
Views
Question
Answered
missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

<a href="javascript;" onClick="if(confirm('Are you sure?'))
alert('You choose yes!');
else alert('You choose no!')">Click me</a>

Try: http://jsfiddle.net/Je8pP/

reyborn
Junior Poster in Training
60 posts since Jan 2006
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 2

i have try you code..it works.. thanks ..but when i put it indise my php code it dosent work.i dont know why? it dosent prompt the message box. it goes to the link directly..

<?php

//if records found, then display data

while($_POST = mysql_fetch_array($result))
{
    echo "<tr>
    <td>".$_POST['pro_id']."</td>
    <td>".$_POST['pro_name']."</td>
    <td>".$_POST['pro_company']."</td>
    <td>".$_POST['pro_date']."</td>
    <td>".$_POST['file_name']."</td>
    <td><a href='".$_POST['quo_file']."' onClick='if(confirm('Are you sure?'))
alert('You choose yes!');
else alert('You choose no!')'>Download</a></td>
    <td>".$_POST['pro_status']."</td>
    <td>".$_POST['pro_by']."</td>
    </tr>";
}
echo "</table>";
echo "<br />";

//<a href="/documents/large_document.pdf">Download the large document</a>filename=\"".$path_parts["basename"]."\"

mysql_free_result ($result);

mysql_close($connectdb);

?>
missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

have i done somthing wrong??..pardon for my code..its a bit messy..

missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi
What does this variable actually $_POST['quo_file'] contains!? does it contain a link!?

-Alex

cigoL..:)
Light Poster
43 posts since Jul 2011
Reputation Points: 9
Solved Threads: 9
Skill Endorsements: 2

@cigoL..:)

yes..the location of the file..

missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

//try your achor like this

echo "<a href='javascript:confirm_download(\'".$_POST['quo_file']."\')'>Download</a>";


//then embed this function to your javascript

function confirm_download(link){
    if(confirm('Are you Sure?')){
        document.location = link;
    }
}
code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

@code739 :

it didnt work..

missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE

<?php

//if records found, then display data

while($_POST = mysql_fetch_array($result))
{
    echo "<tr>
    <td>".$_POST['pro_id']."</td>
    <td>".$_POST['pro_name']."</td>
    <td>".$_POST['pro_company']."</td>
    <td>".$_POST['pro_date']."</td>
    <td>".$_POST['file_name']."</td>
    <td><a href='javascript:confirm_download(".$_POST['quo_file'].")'>Download</a>;</td>
    <td><a href='".$_POST['po_file']."'>download</a></td>
    <td><a href='".$_POST['simul_file']."'>download</a></td>
    <td><a href='".$_POST['pro_file']."'>download</a></td>
    <td>".$_POST['pro_status']."</td>
    <td>".$_POST['pro_by']."</td>
    </tr>";
}
echo "</table>";
echo "<br />";

//<a href="/documents/large_document.pdf">Download the large document</a>filename=\"".$path_parts["basename"]."\"

mysql_free_result ($result);

mysql_close($connectdb);


  //then embed this function to your javascript
    function confirm_download(link){
    if(confirm('Are you Sure?')){
    document.location = link;
    }
    }

?>
missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

1.)dont fortget the \' for \'".$_POST['quo_file']."\' (cause you passing a string)

2.)the javascript function confirm_download() should be inside the <script> tag and it should be outside your php tag

i guess 2 is the cause

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5
<script type="text/javascript">
    //then embed this function to your javascript
    function confirm_download(link){
        if(confirm('Are you Sure?')){
            document.location = link;
        }
    }
</script>

this how it look like

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

@code739 :

It's not working..it dosent have any error..when i click the link nothing happen..

<?php

//if records found, then display data

while($_POST = mysql_fetch_array($result))
{
    echo "<tr>
    <td>".$_POST['pro_id']."</td>
    <td>".$_POST['pro_name']."</td>
    <td>".$_POST['pro_company']."</td>
    <td>".$_POST['pro_date']."</td>
    <td>".$_POST['file_name']."</td>
    <td><a href='javascript:confirm_download(\'".$_POST['quo_file']."\')'>Download</a>;</td>
    <td><a href='".$_POST['po_file']."'>download</a></td>
    <td><a href='".$_POST['simul_file']."'>download</a></td>
    <td><a href='".$_POST['pro_file']."'>download</a></td>
    <td>".$_POST['pro_status']."</td>
    <td>".$_POST['pro_by']."</td>
    </tr>";
}
echo "</table>";
echo "<br />";

//<a href="/documents/large_document.pdf">Download the large document</a>filename=\"".$path_parts["basename"]."\"

mysql_free_result ($result);

mysql_close($connectdb);

?>

    <script type="text/javascript">
    //then embed this function to your javascript
    function confirm_download(link){
    if(confirm('Are you Sure?')){
    document.location = link;
    }
    }
    </script>
missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I. after clicking the anchor did the prompt box shows up? if not

II. if your using a firefox browser press ctr+shift+j
it will display an error

2 then give me the error:

III or try this code below:

function confirm_download(link){
    var box =  confirm('Are you sure?');
    if(box){
        document.location = link;
    }
}
code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

can you give an example value of this variable
$_POST['quo_file']

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

here the error :

Timestamp: 14/11/2012 17:57:05
Error: SyntaxError: illegal character
Source File: javascript:confirm_download(\
Line: 1, Column: 17
Source Code:
confirm_download(\

Timestamp: 14/11/2012 17:57:07
Error: SyntaxError: illegal character
Source File: javascript:confirm_download(\
Line: 1, Column: 17
Source Code:
confirm_download(\

I have try your code but didnt work too..

can you give an example value of this variable
$_POST['quo_file']

What do you mean??

missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

sorry for the mistake
for this line
<td><a href='javascript:confirm_download(\'".$_POST['quo_file']."\')'>Download</a>;</td>
change singlequote to doblequote in like confirm_download(\"".$_POST['quo_file']."\")'

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

@code739 :

Thanks alot..it works

missy_mi
Light Poster
46 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 6 Months Ago by code739, cigoL..:) and reyborn

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1824 seconds using 2.77MB