Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Submit form to different script & window

Reply
Thread Tools

Submit form to different script & window

 
 
Terence Parker
Guest
Posts: n/a
 
      08-17-2004
I have a form which enables users to type in some text in a <TEXTAREA>,
allowing them to use HTML. I have defined two submit buttons - one to
submit as usual, but one which I would like to popup another window and
submit the typed text to different action/script to give a preview.

So far I have done this (removing the excess formatting HTML for clarity):

----------
<SCRIPT language="JavaScript" type="text/javascript">
function submitForm(t) {
window.open("", t, "width=500,height=450");
return true
}
</SCRIPT>


<form action="user_message.php" method="POST" name="UserMessage">
<textarea cols="55" rows="15" name="content"></textarea>
<INPUT type="submit" value="Modify Message">
</form>

<form method="POST" name="Preview" action="preview_message.php"
onsubmit="return submitForm(this.target)" target="preview">
<input type="hidden" name="content" value="">
<input type="submit" name="submit" value="Preview Message">
</form>
-----------

The normal submit obviously works ; the 'preview' submit successfully
pops up another window but because it is submitting a different form it
doesn't contain the value of my textarea.

I have tried adding:
document.form.Preview.content.value =
document.form.UserMessage.content.value;

- but this did not work. In fact, this resulted in the popup losing its
attributes too (i.e. not Hx500;Wx450).

I've also considered putting the 'preview' button as part of the first
form and using an 'OnClick' instead - but couldn't get this working either.

Anyone have any suggestions on how to achieve what I want to do?

Thanks,

Terence
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      08-17-2004
On Tue, 17 Aug 2004 13:17:28 +0800, Terence Parker
<(E-Mail Removed)> wrote:

[snip]

> Anyone have any suggestions on how to achieve what I want to do?


I would suggest NOT trying what you want to do. You have server-side
capabilities, so use them.

Detect on the server whether the form is intended for submission or
preview. If it's the latter, produce a page similar to the editing page,
but with a section that contains a preview of the message. No needless
JavaScript dependency and no reliance on (possibly disabled) pop-ups.

JavaScript, and everything you can do with it, should be considered an
optional component. Relying on it can break a site.

By the way, you probably don't want to do this:

<textarea cols="55" rows="15" name="content"></textarea>
<!-- .... -->
<input type="hidden" name="content" value="">

That is likely[1] to produce a collection of 'content' values, not one.

Mike


[1] I say "likely", because a user agent doesn't have to submit form
controls that have no value. However, some obviously will. I also don't
know if you alter the value with JavaScript.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
submit 1 form to 2 servers or 2 forms to 2 server (1 form each) on 1 submit abansal.itp@gmail.com Javascript 3 06-23-2007 07:29 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com Javascript 2 01-01-2005 06:07 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM
Submit form in different frame to different server Jim Mesara Javascript 0 08-27-2003 08:10 PM



Advertisments