/    Sign up×
Community /Pin to ProfileBookmark

Popup window becomes a whole window

I’m new at javascripting and am trying to submit a form after it has been validated via javascript. I am trying to pass the input info to a popup window but instead get a whole browser window.

Here’e my code, thanks for your help.


—————————

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title> New Document </title>
<script type=”text/javascript” language=”JavaScript”>
<!–
function checkContents(theForm)
{
if (theForm.name.value == “”)
{
alert(“Please enter a name.”);
}
else if (theForm.weight.value == “”)
{
alert(“Please assign a weight.”);
}
else
{
theForm.submit();
}
}

function popWindow(wName){
features =

‘width=400,height=400,toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,copyhistory=no,r

esizable=no’;
pop = window.open(”,wName,features);
if(pop.focus){ pop.focus(); }
return true;
}
–>
</script>
</head>

<body>
<form name=”edititem” action=”popup2.php” method=”post” target=”Details” onSubmit=”return

popWindow(this.target)”>
<input type=”hidden” name =”weight” value=”172″>
<input type=”hidden” name=”name” value=”John”>
<!–<input type=”submit” value=”John”>–>

<input type=”button” value=”Edit Item” onClick=”checkContents(edititem)”>
</form>

</body>
</html>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 11.2006 — Try this:
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt; New Document &lt;/title&gt;
&lt;script type="text/javascript"&gt;
&lt;!--//
function checkContents(theForm) {
if (theForm.uname.value == "")
{
alert("Please enter a name.");
theForm.uname.select();
theForm.uname.focus();
return false;
}
else if (theForm.weight.value == "")
{
alert("Please assign a weight.");
theForm.weight.select();
theForm.weight.focus();
return false;
}
return popWindow(theForm.target);
}

function popWindow(wName) {
features = 'width=400,height=400';
var pop = window.open('',wName,features);
if(pop.focus) pop.focus();
return true;
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="edititem" action="popup2.php" method="post" target="Details"
onSubmit="return checkContents(this)"&gt;
&lt;p&gt;
&lt;input type="text" name="uname" value="John"&gt;
&lt;input type="text" name="weight" value="172"&gt;
&lt;input type="submit" value="Edit Item"&gt;
&lt;/p&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@arzooauthorMay 11.2006 — Thanks!

That did the trick.
Copy linkTweet thisAlerts:
@phpnoviceMay 12.2006 — You're welcome.

Cheers.
Copy linkTweet thisAlerts:
@arzooauthorMay 14.2006 — I've modified the code in order to have a list of names and an edit button across each. However, instead of using the submit button, the edit button serves as the control to call the javascript (sorry, this is the method i'm used to doing -- using the submit action from javacript).

I've tried figuring out how to make the the code work using the code provided by phpnovice above but havent been able to get it to work.

Is there a way to make the editName function submit the values to the popup window?

thanks.

Here's my code:
------------------------



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title> New Document </title>

<script type="text/javascript">

<!--//


function editName(theForm, firstname, middlename , lastname)

{

alert (firstname+" "+middlename+" "+lastname);

theForm.firstname.value = firstname;


theForm.middlename.value = middlename;

theForm.lastname.value = lastname;

theForm.action = "popup2.php";
theForm.submit();

}


function popWindow(wName) {

w=400;

h=400;

l=(screen.width-w)/2;

t=(screen.height-h)/2;

features='width='+w+',height='+h+',left='+l+',top='+t;

var pop = window.open(theFile,wName,features);

if(pop.focus) pop.focus();

return true;

}

//-->

</script>

</head>

<body>

<form name="edititem" method="post">

<table border=1>

<tr>

<td>Name</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>John Henry Smith</td>

<td><font size='2'><input type='button' value='Edit' onClick='editName(edititem, "John","Henry","Smith")'></td>

</tr>

<tr>

<td>William James Hawthorne</td>

<td><font size='2'><input type='button' value='Edit' onClick='editName(edititem, "William","James","Hawthorne")'></td>

</tr>

<tr>

<td>Jerry Lee Daniels </td>

<td><font size='2'><input type='button' value='Edit' onClick='editName(edititem, "Jerry","Lee","Daniels")'></td>

</tr>

</table>

<input type='hidden' name='firstname' value="">

<input type='hidden' name='middlename' value="">

<input type='hidden' name='lastname' value="">


</form>

</body>

</html>
Copy linkTweet thisAlerts:
@phpnoviceMay 14.2006 — Just change your FORM tag to this:

<form name="edititem" action="popup2.php" method="post" target="EditDetails">

and change this:

theForm.action = "popup2.php";

to this:

popWindow(theForm.target);

and change this:

var pop = window.open(theFile,wName,features);

to this:

var pop = window.open("", wName, features);
Copy linkTweet thisAlerts:
@arzooauthorMay 15.2006 — Thanks again.

Your help is very much appreciated!
×

Success!

Help @arzoo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...