Results 1 to 13 of 13

Thread: on click

Hybrid View

  1. #1

    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

  2. #2
    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.

  3. #3

    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?

  4. #4
    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.

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