Return Bool From Event Listener

Go To StackoverFlow.com

0

So right now I am submitting a form, onSubmit I am disappearing the form (display none) and showing a link. What I want to do is return true to the form (so it can submit) when a user clicks on the link, so I want to return from the event listener. But the eventlistener is always true since it will always attach. Anybody have suggestions on the best way to do this?

<form name="request" action="http://testurl.com" method="POST" onSubmit="return test()">
    <input type="text" name="Name" size="10" />
    <input type="submit" name="submit" value="Submit" />
</form>

<div id="link">
    <a href="test.exe" title="download">Download</a>
</div>

-JS-

function test(){
    document.request.style.display = "none";
    document.getElementById('link').style.display = "block";
    return false;
}
2012-04-03 20:53
by Howdy_McGee
Why do you need the return false in test() - Tuan 2012-04-03 21:42


1

Use JQuery... Here is some changings..

<form name="request">
    <input type="text" name="Name" size="10" />
    <input type="button" id="submit" value="Submit" />
</form>

<div id="link">
    <a href="test.exe" title="download">Download</a>
</div>​

Here is your Javascript code...

function test(){
    document.request.style.display = "none";
    document.getElementById('link').style.display = "block";
    return true;
}


$("#submit").on('click', function (){
    $.ajax({
        url: 'http://www.youractionsite.com',
        type: 'POST',
        data: 'name='+$("input[name='Name']").val(),
        success: function(){
             test();
        }
    });     
});
​

It is tested... code is working...

2012-04-03 21:32
by Shahrukh
Working Sample... http://jsfiddle.net/extremerose71/McsS8/6 - Shahrukh 2012-04-03 21:35


0

In the onClick of your link, you can do $("#formId").submit(); Is that what you're after?

2012-04-03 20:57
by Adam Shiemke
Even if I already have a return false on my OnSubmit= function - Howdy_McGee 2012-04-03 20:59
Probably. Try it out and see what happens - Adam Shiemke 2012-04-03 21:01
I had no luck with it. I updated my question to reflect some of my code - Howdy_McGee 2012-04-03 21:08