I have a form(formpage1.asp) where I need to prevent the form from submitting at first, because I need to check if a pdf file is selected or not.
I can NOT send the post via a app.reguest, I need to send it on the page like this.
<form action="laxa/laxa1.asp" method="POST" ENCTYPE="multipart/form-data" id="laxaform" >
<input type="file" name="file2" id="laxa2" />
<button type="submit">SEND</button>
If a file is not selected then I want to post it to the page in the form, (laxa1.asp) and if a file is selected then I want to post it to (laxa2.asp).
So I need from my js file be able to send it as if I clicked on the button on the page.
But the problem I have is that it is actually loading the laxa2.asp, not just sending the post request to it.
So I want to submit the post request without navigating to/loading the page in the browser.
So I have tested with this.
$$('#laxaform').submit(function(event) {
event.preventDefault();
var thepdffile = $$(page.el).find('#laxa2').val();
if (thepdffile){
//app.dialog.alert("a file is selected")
$$(page.el).find('#laxaform').attr('action','laxa/laxa2.asp');
}else{
//if no pdf file selected, send to page laxa1.asp
//app.dialog.alert("no file selected")
}
app.dialog.confirm('Send the form? ','SKOLAPPEN', function () {
//this will load the page, not just send the post request to it..so how do I prevent it from loading?
$$('#laxaform').submit();
//I have tryed to set event.preventDefault(); here but then it is not working at all to send.
});
});
Any input appreciated, thanks a lot!