Results 1 to 13 of 13

Thread: on click

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    on click

    Code:
                <input name="Save" type="submit" class="style11" id="Save" value="Save announcement" onclick="alert(form.textarea.value)" />
    onclick="alert(form.textarea.value)"

    that just msgboxes with the announcement (textarea text) on the msgbox.

    what im trying to do is make the msgbox appear with a yes/no option so the user can decide to save it or not..

    if they want to save it (clicking yes button) i want to perform the function _save which is a php function like this

    PHP Code:
    <?
    function _save(blah) { }
    ?>
    any ideas guys?

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: on click

    Use confirm() instead of alert().
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: on click


  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: on click

    Quote Originally Posted by penagate
    I knew you were going to post a link to that thread
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: on click

    Doesn't my predictability sicken you? It does me

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: on click

    i got a weird problem

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    function processAnn () {
    	answer = confirm('Confirm ' + form1.textarea.value)
    	
    	if (answer == 1) {
    		<?
    		$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
    		$result = mysql_query($query) or die("Query error<br/>" . mysql_error());
    		
    		?> 
    	}
    }
    
    </SCRIPT>
    Code:
    <input name="Save" type="submit" class="style11" id="Save" value="Save announcement" onclick="processAnn()" />
    now evertime i refresh the page, it ust writes 'hi' to the database :S

    so it keeps on doing this

    $query = "UPDATE `announcement` SET `Announcement` = 'hi'";

    but it should only do that when i click 'Ok' in the confirm msgbox

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: on click

    I suggest you read this: PHP Tutorial and pay careful attention to the parts that explain when and where PHP code is executed.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: on click

    Quote Originally Posted by Pouncer
    i got a weird problem

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    function processAnn () {
    	answer = confirm('Confirm ' + form1.textarea.value)
    	
    	if (answer == 1) {
    		<?
    		$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
    		$result = mysql_query($query) or die("Query error<br/>" . mysql_error());
    		
    		?> 
    	}
    }
    
    </SCRIPT>
    Code:
    <input name="Save" type="submit" class="style11" id="Save" value="Save announcement" onclick="processAnn()" />
    now evertime i refresh the page, it ust writes 'hi' to the database :S

    so it keeps on doing this

    $query = "UPDATE `announcement` SET `Announcement` = 'hi'";

    but it should only do that when i click 'Ok' in the confirm msgbox
    Ajax isn't that easy.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: on click

    ok, but i dont see why it cant work properly, the page is a .php page anyway

    cant i have php inside javascript?

    how can i go about doing this properly then?

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: on click

    Quote Originally Posted by Pouncer
    cant i have php inside javascript?
    Go back and read the tutorial again.

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: on click

    Quote Originally Posted by Pouncer
    ok, but i dont see why it cant work properly, the page is a .php page anyway

    cant i have php inside javascript?

    how can i go about doing this properly then?
    PHP is executed before the pages is sent to the browser. The HTML source code is the output of your PHP script. If you want PHP to execute on a Javascript event you'll either need to use Ajax (which as you are a beginner I do not recommend) or use a link:

    Code:
    <a href="page.php?action=updateannounce&set=hi">Update Announcement</a>
    If your page you'll need to have something like this:
    PHP Code:
    if (isset($_GET['action'])){
        switch (
    $_GET['action']) {
            case 
    'updateannounce':
                
    update_announcement(@$_GET['set']);
                break;
        }
    }

    function 
    update_announcement($text)
    {
        
    $text=mysql_escape_string($text);

        
    $query "UPDATE `announcement` SET `Announcement` = '$text'";
        
    $result mysql_query($query) or die("Query error<br/>" mysql_error());

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: on click

    Ok,

    how can i go about doing this properly then?

    edit * Thanks visualAid

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: on click

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width