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;
}
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...
In the onClick of your link, you can do $("#formId").submit(); Is that what you're after?