spectrumcare
asked on
change form target with jquery
Hello I have an html form with an onsubmit to validate the fields. If the form validates I have the form opening in a popup window.
So what I am doing to when the user clicks submit it does the check form. If that comes back with no validation issues the form opens a popup window that does some printing. On the popup page I have onload function that the confirmPrint function on the parent page to open up a modal window to ask if the pages printed properly. When the modal window closes I am calling the loaddata function to reload the page data. If the user does some other things on the main page the click submit and if the validation fails a blank tab opens. This is happening because I changed the form target to the formpopup. Is there a way I can change the form target back to what it was before.
I tried
and
and quite a few more things in the loaddata and the checkform function and I can't get anything to work properly.
function checkform()
{
some validation
$('#form1').submit(function() {
window.open('', 'formpopup', '');
this.target = 'formpopup';
});
}
function confirmPrint(theID)
{
var sURL = "checkifprintedModal.cfm?myID="+theID;
showPopWin(sURL,600,375,null);
}
function loaddata()
{
ajax to load table form
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("mydata").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getmystuff.cfm?accountID="+encodeURIComponent(accountID),true);
xmlhttp.send();
}
<body onload="loaddata();">
<form id="form1" target="_blank" onsubmit="return checkform()">
<div id="mydata">
<table>
<!--- ajax data goes here --->
<tr>
<td> <input type="submit" value="Submit">
</tr>
</table>
</div>
<table>
</form>
</body>
So what I am doing to when the user clicks submit it does the check form. If that comes back with no validation issues the form opens a popup window that does some printing. On the popup page I have onload function that the confirmPrint function on the parent page to open up a modal window to ask if the pages printed properly. When the modal window closes I am calling the loaddata function to reload the page data. If the user does some other things on the main page the click submit and if the validation fails a blank tab opens. This is happening because I changed the form target to the formpopup. Is there a way I can change the form target back to what it was before.
I tried
$('#form1').submit(function() {
$('#this').target="new";
});
and var targetvalue = "new";
$('#form1').prop("target", targetvalue);
and
$('#form1').submit(function() {
$('#form1.target')="new";
});
with this I am getting js error saying "Uncaught ReferenceError: Invalid left-hand side in assignment"and quite a few more things in the loaddata and the checkform function and I can't get anything to work properly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=
}
</script>
<a href="JavaScript:newPopup(