Form Confirmation Problem

K

kelvin

Hi,

I'm having this problem and I can't seem to solve it.

I've created a confirmation page. The page displays the form field
data and has
2 links - OK (to continue) and Cancel (go back to form).

The OK button will continue to validate the form values, cancel to
close window.
The problem starts here. I get script error and the error message
doesn't tell me
what's the problem.

Also how do I include the form action code?

Can someone help me, pls? Your help/guidance is much appreciated!

Rgds,
Kelvin


<SCRIPT LANGUAGE="JavaScript">
<!--
function display()
{
var x;
DispWin = window.open('','ConfirmPage',
'toolbar=no,status=no,width=300,height=200')
message = "<ul><li><b>destination: </b>" +
document.form1.destination.value;
message += "<li><b>Weight: </b>" + document.form1.Weight.value;
message += "<li><b>departure: </b>" + document.form1.departure.value
+ "<br>";

message += "\nChoose OK to submit these values, or\n"
message += "Cancel to return to the form. <br><br>";
message += "<a href='javascript:eek:nclick='opener.document.form1.checkForm1();self.close();''>OK</a>
"; //ERROR ON THIS LINE.

DispWin.document.write(message);
}


function checkForm1()
{
if(document.form1.destination.value == "")
{
alert("Destination must not contain numbers at all.");
document.form1.destination.focus();
return false;
}

if(document.form1.departure.value == "")
{
alert("Origin must not contain numbers at all.");
document.form1.departure.focus();
return false;
}

if(document.form1.station.value == "")
{
alert("Please provide the station.");
document.form1.station.focus();
return false;
}
}

// End -->
</script>



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

<input name="destination" type="text" value="US">

<input name="Weight" type="text" value="456">

<input name="departure" type="text" value="UK">

<input name="submit" type="submit" value="Quote" onClick="display();">

</form>
 
K

kaeli

Hi,

I'm having this problem and I can't seem to solve it.

You have incorrectly nested quotes, among other problems.
<SCRIPT LANGUAGE="JavaScript">

<script type="text/javascript">
The language attribute is deprecated.


I don't think there is a single human being using a browser that doesn't
understand script any more. You can drop the comments.
There is a difference between disabled script and not understanding script.
Browsers used to not understand script. I think the last browser that didn't
get it was netscape 3 or something else very, very old. ;)
function display()
{
var x;
DispWin = window.open('','ConfirmPage',
'toolbar=no,status=no,width=300,height=200')

You understand the risks with using window.open, right?
message = "<ul><li><b>destination: </b>" +
document.form1.destination.value;

Invalid HTML will be written to the new page if you don't stick the right
tags in there. You seem to have forgotten the html, head, and body tags.
message += "<li><b>Weight: </b>" + document.form1.Weight.value;
message += "<li><b>departure: </b>" + document.form1.departure.value
+ "<br>";

message += "\nChoose OK to submit these values, or\n"
message += "Cancel to return to the form. <br><br>";
message += "<a href='javascript:eek:nclick='opener.document.form1.checkForm1();self.close();''>OK</a>
"; //ERROR ON THIS LINE.

You didn't nest the quotes right. Backslash-escape the singe quotes embedded
in the single quotes.
And you understand the risks with using javascript as an anchor target,
right?

message += "<a href='javascript:eek:nclick=\'opener.document.form1.checkForm1
();self.close();\''>OK said:
{
if(document.form1.destination.value == "")
{
alert("Destination must not contain numbers at all.");
document.form1.destination.focus();
return false;
}

Returning false cancels form submission IF you put the validation in onSubmit
with a return and the submission is done from a submit button. You aren't
doing that, plus you close the window regardless of the return value.
Drop the self.close all by itself. It will close the window even if the form
didn't submit. Put it in the validation/submit routine and call only if
everything passed validation.
Don't bother returning any value if you're keeping this format.

Do this instead:
message += "<a href='javascript:eek:nclick=\'opener.document.form1.checkForm1();
\''>OK</a>";

checkForm1: (pseudocode)
do all the checks
if (any are bad)
return
else
set action
submit form in opener
close self
end if

--
 
M

Michael Winter

I think the last browser that didn't get it was netscape 3 or something
else very, very old. ;)

According to the Netscape reference, Netscape 2.0 implemented JavaScript
1.0. That means that you'd have to go back to the first version of
Netscape to find a browser that couldn't execute a script. I think "very,
very old" is an understatement!

[snip]
Invalid HTML will be written to the new page if you don't stick the
right tags in there. You seem to have forgotten the html, head, and body
tags.

You also forgot to mention that when a script placed directly inside a
HTML document contains the sequence, "</", it should be escaped to ensure
no browser mistakes that for the end of the SCRIPT element. The line above
should read:

message = "<ul><li><b>destination: <\/b>"
+ document.form1.destination.value;

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top