1,105,320 Community Members

how to prompt a confirm dialog box using links not buttons

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi there,

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

Member Avatar
reyborn
Junior Poster in Training
60 posts since Jan 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 3 [?]
 
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/

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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);

?>
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
0
 

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

-Alex

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@cigoL..:)

yes..the location of the file..

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
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;
    }
}
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@code739 :

it didnt work..

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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;
    }
    }

?>
Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
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

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
0
 
<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

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@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>
Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
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;
    }
}
Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
0
 

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

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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??

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
1
 

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']."\")'

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@code739 :

Thanks alot..it works

Question Answered as of 1 Year Ago by code739, reyborn and cigoL..:)
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article