|
-
Jun 15th, 2006, 04:17 AM
#1
Thread Starter
Frenzied Member
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?
-
Jun 15th, 2006, 04:36 AM
#2
Re: on click
Use confirm() instead of alert().
-
Jun 15th, 2006, 04:51 AM
#3
-
Jun 15th, 2006, 04:58 AM
#4
Re: on click
 Originally Posted by penagate
I knew you were going to post a link to that thread
-
Jun 15th, 2006, 04:59 AM
#5
Re: on click
Doesn't my predictability sicken you? It does me
-
Jun 15th, 2006, 06:12 AM
#6
Thread Starter
Frenzied Member
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
-
Jun 15th, 2006, 06:13 AM
#7
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.
-
Jun 15th, 2006, 06:17 AM
#8
Re: on click
 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.
-
Jun 15th, 2006, 06:19 AM
#9
Thread Starter
Frenzied Member
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?
-
Jun 15th, 2006, 06:22 AM
#10
Re: on click
 Originally Posted by Pouncer
cant i have php inside javascript?
Go back and read the tutorial again.
-
Jun 15th, 2006, 06:32 AM
#11
Re: on click
 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());
}
-
Jun 15th, 2006, 06:32 AM
#12
Thread Starter
Frenzied Member
Re: on click
Ok,
how can i go about doing this properly then?
edit * Thanks visualAid
-
Jun 15th, 2006, 06:34 AM
#13
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|