Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to stop refreshing when a form ele is clicked

    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
    PHP 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
    Last edited by Diod; 12-18-2005 at 02:12 PM.

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found it;

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


  •  

    Posting Permissions

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