Welcome Guest, Not a member yet? Register   Sign In
Problem with page submition
#1

[eluser]halwaraj[/eluser]
I have this Page with following code in a view file:

Code:
<table>
            <tr>
                <td>
                    &lt;?php echo form_button($resetButton,"",$js_Reset); ?&gt;
                </td>
            </tr>
        </table>

The following is the array being passed to the form_button function above.

Code:
$resetButton = array(
      'name' => 'resetButton',
      'id' => 'resetButton',
      'value' => 'false',
      'type' => '',
      'content' => 'Reset'
    );

The following is the javascript code that goes into the function.

Code:
$js_Reset = 'onclick="resetClicked()"';

The javascript code for the function refered.

Code:
function resetClicked(){
        alert("RESET CLICKED . . .");
        return false;
    }

So, Now, the problem that I am facing is that eventhough I return a false in the js function, when I click the Reset button, the page gets submitted.

My question is why does it get submitted eventhough I return false from the js function. Any ideas?
#2

[eluser]pistolPete[/eluser]
In case you just want to reset you form, why don't you use:
Code:
&lt;input type="reset" value="Reset"&gt;

But your javascript is incorrect:
The button's onClick event has to return false in order to stop executing, but only your function is returning false, not the event!
Change it to:
Code:
$js_Reset = 'onclick="return resetClicked();"';
#3

[eluser]halwaraj[/eluser]
If you see the last code snippet, I have returned false from the actual js function.
#4

[eluser]TheFuzzy0ne[/eluser]
Yes, but you need to return the return value of the function to the onclick event.

EDIT: What you're doing is the difference between using:
Code:
onclick="FALSE;"

and

Code:
onclick="return FALSE;"

The latter will work, the other will not.
#5

[eluser]halwaraj[/eluser]
This means I always got to return something from a js function. If I dont return anything, it'll just submit.
OK thanks alot guys for the quick help.




Theme © iAndrew 2016 - Forum software by © MyBB