...

View Full Version : How to stop refreshing when a form ele is clicked



Diod
12-18-2005, 12:26 PM
I'm making a small guestbook with php and mysql, but now im currently adding the smileys. I got everything to work so that the smileys BB code get added to the textarea, but whenever i press the smiley it reloads the page, which means it always queries the mysql server. How do i stop this?

This is my code

printf('
<script language="JavaScript">
function AddText(TextArea, Value) {
window.document.form1.textarea.value = window.document.form1.textarea.value + Value;
}
</script>

<table align="center" border="1">
<tr>
<td><form id="form1" name="form1" method="post" action="">
<p align="center">Post een bericht </p>
<p align="center">Naam:
<label>
<input type="text" name="textfield1" size="30" />
</label>
</p>
<p align="center">Website:
<label>
<input type="text" name="textfield2" size="45" value="http://"/>
</label>
</p>
<p align="center">
<label></label>
<hr align="center" />');

while ($smiley = mysql_fetch_array($smileyquery)) {
if (!is_float($i / $maxsmileys)) echo '<br><input name="imageField" class="smileys" type="image" src="images/smileys/' . $smiley[URL] . '" alt="' . $smiley[Name] . '" OnClick="AddText(textarea, \'' . $smiley[Short] . '\');"/>';
else echo '<input name="imageField" class="smileys" type="image" src="images/smileys/' . $smiley[URL] . '" alt="' . $smiley[Name] . '" OnClick="AddText(textarea, \'' . $smiley[Short] . '\');"/>';
$i = $i + 1;
}

printf('
</p>
<p align="center">
<label>
<textarea name="textarea" cols="50" rows="6"></textarea>
</label>
</p>
<p align="center">
<label>
<input type="submit" name="Submit" value="Verzend" />
</label>
<label>
<input type="reset" name="Submit2" value="Reset" />
</label>
</p>
</form></td>
</tr>
</table>
');


So basically, what it does is add the smileys as an imagefield button, and when pressed it adds the BB code to the textarea. But it refreshes so in the end, the textarea stays empty

Diod
12-18-2005, 03:19 PM
I found it;

<form id="form1" name="form1" method="post" action="" onSubmit="return false;"> The red part should've been there :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum