Empty variables before publishing using jQuery ONLY

advertisements

I have checked this question in SOF, How to prevent form element from sending some fields we don't want?

Here is my code

index.php

    <script type="text/javascript">
    $(formElement).submit(function() {
        ... how to do the jquery stuff..
        return true;
    });

    <?php
    $my_variable_with_value1 = 'abc';
    $my_variable_with_value2 = 'def';
    $another_one_variable = 'mango';
     ?>
    <form method="post" action="process.php">
    <input type="text" id="id1" name="name1" value="<?php echo $my_variable_with_value1 ?>"  />
    <input type="text" id="id2" name="name2" value="<?php echo $my_variable_with_value2 ?>"  />
    <input type="submit" value="Submit" />
    </form>

I need to do the following 1. Before the page is submitted i need to unset/empty the variable values using JQUERY ONLY 2. I have to show the variable in index.php and not in the next page process.php

In other words, HOW CAN I EMPTY THE VARIABLES $my_variable_with_value1 AND $another_one_variable BEFORE PAGE SUBMIT USING JQUERY

Thanks, Kimz


Instead of directly submitting the form using

$(formElement).submit(function() {

call an onclick function in button as:

 <input type="submit" value="Submit" onclick="submitform()" />

and in the js function you can set the value of input fields to empty like:

function submitform()
{
    $('#id1').val('');
    $('form').submit();
}