hi there,

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

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

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

?>

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

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

-Alex

@cigoL..:)

yes..the location of the file..

//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 :

it didnt work..

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

?>

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

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

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>

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

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

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

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 :

Thanks alot..it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.