I would like you to ask for a ltl bit assistance. Here is my problem:
I have a form with few input lines and textarea, and after a form i have three buttons: [Close] [Preview] [Submit]
And here is what i need:
Then visitor **** [Preview]- the forms data should be passed to pop_up window for preview (something like submited to pop up window) for example "pop_up_preview.php" but the main page should be left at it is (for editing data)
But then user **** [Submit], a forms data is passed to another regular page, for example "validate_data.php"
Maybe someone knows how to deal with that?
Script: submit form data TO popup
Hip hip, i have done it yeeeee, even javasript experts (from http://www.allexperts.com) was unable to help me, but i have done it, and i dont think that i'm intermediate user in JS, i'm a n00b in javascript, but i've done it
so javascript code:
Form header:
Here is very long code for my news edition: Sorry, some parts is in lithuanian, but the main idea is clear. I think for someone it will be very valuable. It uses PHPbb code. So, here is is (alt+c)";
l_help = "List:
o_help = "Ordered list:
p_help = "Įdėti paveiksliuką: [img]http://paveiksliuko_adresas[/img] (alt+p)";
w_help = "Įdėti adresą: http://adresas arba Nuorodos tekstas (alt+w)";
a_help = "Udaryti visus atvirus tagus";
s_help = "Patarimas:tekstą galite formuoti jį pabraukę ir nuspaudę atitinkamą mygtuką";
t_help = "Temos pavadinimas";
f_help = "Font size: [size=x-small]small text[/size]";
d_help = "Rodyti visus veidelius";
// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('', '', '', '', '', '', '[bquote]', '[/bquote]', '', '
imageTag = false;
// Shows the help messages in the helpline window
function helpline(help) {
****.post.helpbox.value = eval(help + "_help");
}
// Replacement for arrayname.length property
function getarraysize(thearray) {
for (i = 0; i < thearray.length; i++) {
if ((thearray == "undefined") || (thearray == "") || (thearray == null))
return i;
}
return thearray.length;
}
// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
thearray[ getarraysize(thearray) ] = value;
}
// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
thearraysize = getarraysize(thearray);
retval = thearray[thearraysize - 1];
delete thearray[thearraysize - 1];
return retval;
}
function checkForm() {
formErrors = false;
if (****.post.subject.value.length < 3) {
formErrors = "Juk neuraei temos pavadinimo! Įraas turi būti sudarytas i daugiau kaip 3 enklų";
}
if (****.post.message.value.length < 5) {
formErrors = "Juk nieko neįraei! Įraas turi būti sudarytas i daugiau kaip 5 enklų";
}
if (formErrors) {
alert(formErrors);
return false;
} else {
bbstyle(-1);
//formObj.preview.disabled = true;
//formObj.submit.disabled = true;
return true;
}
}
function emoticon(text) {
var txtarea = ****.post.message;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
function bbfontstyle(bbopen, bbclose) {
var txtarea = ****.post.message;
if ((clientVer >= 4) && is_ie && is_win) {
theSelection = ****.selection.createRange().text;
if (!theSelection) {
txtarea.value += bbopen + bbclose;
txtarea.focus();
return;
}
****.selection.createRange().text = bbopen + theSelection + bbclose;
txtarea.focus();
return;
}
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbopen, bbclose);
return;
}
else
{
txtarea.value += bbopen + bbclose;
txtarea.focus();
}
storeCaret(txtarea);
}
function bbstyle(bbnumber) {
var txtarea = ****.post.message;
txtarea.focus();
donotinsert = false;
theSelection = false;
bblast = 0;
if (bbnumber == -1) { // Close all open tags & default button names
while (bbcode[0]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('****.post.addbbcode' + butnumber + '.value');
eval('****.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
}
imageTag = false; // All tags are closed including image tags
txtarea.focus();
return;
}
if ((clientVer >= 4) && is_ie && is_win)
{
theSelection = ****.selection.createRange().text; // Get text selection
if (theSelection) {
// Add tags around selection
****.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
txtarea.focus();
theSelection = '';
return;
}
}
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
return;
}
// Find last occurance of an open tag the same as the one just ****
for (i = 0; i < bbcode.length; i++) {
if (bbcode == bbnumber+1) {
bblast = i;
donotinsert = true;
}
}
if (donotinsert) { // Close all open tags up to the one just **** & default button names
while (bbcode[bblast]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('****.post.addbbcode' + butnumber + '.value');
eval('****.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
imageTag = false;
}
txtarea.focus();
return;
} else { // Open tags
if (imageTag && (bbnumber != 14)) { // Close image tag before adding another
txtarea.value += bbtags[15];
lastValue = arraypop(bbcode) - 1; // Remove the close image tag from the list
****.post.addbbcode14.value = "Img"; // Return button back to normal state
imageTag = false;
}
// Open tag
txtarea.value += bbtags[bbnumber];
if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
arraypush(bbcode,bbnumber+1);
eval('****.post.addbbcode'+bbnumber+'.value += "*"');
txtarea.focus();
return;
}
storeCaret(txtarea);
}
// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2)
selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
return;
}
// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/vie ... 52/fid/130
function storeCaret(textEl) {
if (textEl.createTextRange) textEl.caretPos = ****.selection.createRange().duplicate();
}
//pop-up window for preview
function popup() {
win = window.open('','myWin','toolbars=0');
****.post.action='preview.php';
****.post.target='myWin';
****.post.submit();
****.post.action='?mod=naujienos&mod_file=done.php';
****.post.target='_self';
}
//-->
</script>
<form method="post" name="post" action="preview.php" target="_self" onsubmit="return checkForm(this)">
so javascript code:
Code: Select all
//pop-up window for preview
function popup() {
win = window.open('','myWin','toolbars=0');
****.post.action='preview.php';
****.post.target='myWin';
****.post.submit();
****.post.action='validate.php';
****.post.target='_self';
}
Code: Select all
<form method="post" name="post" action="validate.php" target="_self" >
And here is the buttons code:here goes whatever inputs, selects, textareas and so on
Code: Select all
<input type="button" value="Cancel" ****="history.go(-1)"> <input type="button" name="prev" class= value="Preview" ****="popup(); " /> <input type="submit" name="post" value="Submit" />
</form>
Here is very long code for my news edition: Sorry, some parts is in lithuanian, but the main idea is clear. I think for someone it will be very valuable. It uses PHPbb code. So, here is is
Code: Select all
<script language="JavaScript" type="text/javascript">
<!--
// bbCode control by
// subBlue design
// [url]www.subBlue.com[/url]
// Startup variables
var imageTag = false;
var theSelection = false;
// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
// Helpline messages
b_help = "Pastorintas tekstas: [b]tekstas[/b] (alt+b)";
i_help = "Paverstas kursyvu tekstas: [i]tekstas[/i] (alt+i)";
u_help = "Pabrauktas tekstas: [u]tekstas[/u] (alt+u)";
q_help = "Citatos tekstas: [bquote]tekstas[/bquote] (alt+q)";
c_help = "Code display: [code]code
l_help = "List:
- text
o_help = "Ordered list:
- text
p_help = "Įdėti paveiksliuką: [img]http://paveiksliuko_adresas[/img] (alt+p)";
w_help = "Įdėti adresą: http://adresas arba Nuorodos tekstas (alt+w)";
a_help = "Udaryti visus atvirus tagus";
s_help = "Patarimas:tekstą galite formuoti jį pabraukę ir nuspaudę atitinkamą mygtuką";
t_help = "Temos pavadinimas";
f_help = "Font size: [size=x-small]small text[/size]";
d_help = "Rodyti visus veidelius";
// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('', '', '', '', '', '', '[bquote]', '[/bquote]', '
Code: Select all
', '
- ', '
- ', '
imageTag = false;
// Shows the help messages in the helpline window
function helpline(help) {
****.post.helpbox.value = eval(help + "_help");
}
// Replacement for arrayname.length property
function getarraysize(thearray) {
for (i = 0; i < thearray.length; i++) {
if ((thearray == "undefined") || (thearray == "") || (thearray == null))
return i;
}
return thearray.length;
}
// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
thearray[ getarraysize(thearray) ] = value;
}
// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
thearraysize = getarraysize(thearray);
retval = thearray[thearraysize - 1];
delete thearray[thearraysize - 1];
return retval;
}
function checkForm() {
formErrors = false;
if (****.post.subject.value.length < 3) {
formErrors = "Juk neuraei temos pavadinimo! Įraas turi būti sudarytas i daugiau kaip 3 enklų";
}
if (****.post.message.value.length < 5) {
formErrors = "Juk nieko neįraei! Įraas turi būti sudarytas i daugiau kaip 5 enklų";
}
if (formErrors) {
alert(formErrors);
return false;
} else {
bbstyle(-1);
//formObj.preview.disabled = true;
//formObj.submit.disabled = true;
return true;
}
}
function emoticon(text) {
var txtarea = ****.post.message;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
function bbfontstyle(bbopen, bbclose) {
var txtarea = ****.post.message;
if ((clientVer >= 4) && is_ie && is_win) {
theSelection = ****.selection.createRange().text;
if (!theSelection) {
txtarea.value += bbopen + bbclose;
txtarea.focus();
return;
}
****.selection.createRange().text = bbopen + theSelection + bbclose;
txtarea.focus();
return;
}
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbopen, bbclose);
return;
}
else
{
txtarea.value += bbopen + bbclose;
txtarea.focus();
}
storeCaret(txtarea);
}
function bbstyle(bbnumber) {
var txtarea = ****.post.message;
txtarea.focus();
donotinsert = false;
theSelection = false;
bblast = 0;
if (bbnumber == -1) { // Close all open tags & default button names
while (bbcode[0]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('****.post.addbbcode' + butnumber + '.value');
eval('****.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
}
imageTag = false; // All tags are closed including image tags
txtarea.focus();
return;
}
if ((clientVer >= 4) && is_ie && is_win)
{
theSelection = ****.selection.createRange().text; // Get text selection
if (theSelection) {
// Add tags around selection
****.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
txtarea.focus();
theSelection = '';
return;
}
}
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
return;
}
// Find last occurance of an open tag the same as the one just ****
for (i = 0; i < bbcode.length; i++) {
if (bbcode == bbnumber+1) {
bblast = i;
donotinsert = true;
}
}
if (donotinsert) { // Close all open tags up to the one just **** & default button names
while (bbcode[bblast]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('****.post.addbbcode' + butnumber + '.value');
eval('****.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
imageTag = false;
}
txtarea.focus();
return;
} else { // Open tags
if (imageTag && (bbnumber != 14)) { // Close image tag before adding another
txtarea.value += bbtags[15];
lastValue = arraypop(bbcode) - 1; // Remove the close image tag from the list
****.post.addbbcode14.value = "Img"; // Return button back to normal state
imageTag = false;
}
// Open tag
txtarea.value += bbtags[bbnumber];
if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
arraypush(bbcode,bbnumber+1);
eval('****.post.addbbcode'+bbnumber+'.value += "*"');
txtarea.focus();
return;
}
storeCaret(txtarea);
}
// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2)
selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
return;
}
// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/vie ... 52/fid/130
function storeCaret(textEl) {
if (textEl.createTextRange) textEl.caretPos = ****.selection.createRange().duplicate();
}
//pop-up window for preview
function popup() {
win = window.open('','myWin','toolbars=0');
****.post.action='preview.php';
****.post.target='myWin';
****.post.submit();
****.post.action='?mod=naujienos&mod_file=done.php';
****.post.target='_self';
}
//-->
</script>
<form method="post" name="post" action="preview.php" target="_self" onsubmit="return checkForm(this)">
Tema:<input type="text" name="subject" size="45" value="" class="input" style="width:390px" onMouseOver="helpline('t')" />
<table width="450" border="0" cellspacing="0" cellpadding="2">
<tr align="center" valign="middle">
<td><span class="genmed">
<input type="button" class="submit" accesskey="b" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+b" name="addbbcode0" value=" B " style="font-weight:bold; width: 30px" ****="bbstyle(0)" onMouseOver="helpline('b')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="i" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+i" name="addbbcode2" value=" i " style="font-style:italic; width: 30px" ****="bbstyle(2)" onMouseOver="helpline('i')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="u" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+u" name="addbbcode4" value=" u " style="text-decoration: underline; width: 30px" ****="bbstyle(4)" onMouseOver="helpline('u')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="q" name="addbbcode6" value="Citata" style="width: 60px" ****="bbstyle(6)" onMouseOver="helpline('q')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="p" name="addbbcode14" value="Img" style="width: 40px" ****="bbstyle(14)" onMouseOver="helpline('p')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline; width: 40px" ****="bbstyle(16)" onMouseOver="helpline('w')" />
</span></td>
</tr>
<tr>
<td colspan="9">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Veideliai</td>
<td nowrap="nowrap" align="right"><span class="gensmall">[url=javascript:bbstyle(-1)]Udaryti tagus[/url]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="9"> <span class="gensmall">
<input type="text" name="helpbox" size="45" maxlength="100" style="width:450px; font-size:9px; background-color:#F4F5FA;" readonly class="input" value="Patarimas: Teksto formavimo stilius gali būti pritaikytas paymėtam tekstui" onMouseOver="helpline('s')" />
</span></td>
</tr>
<tr>
<td colspan="9"><span class="gen">
<textarea name="message" rows="15" cols="35" wrap="soft" style="width:450px" tabindex="3" class="input" onselect="storeCaret(this);" ****="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
</span></td>
</tr>
</table><input type="button" value="Ataukti" class="submit" ****="history.go(-1)"><input type="button" name="post" class="submit" value="Paiūrėti" ****="popup(); " /><input type="submit" name="post" class="submit" value="Įrayti" />
</form>[/code]
<table width="450" border="0" cellspacing="0" cellpadding="2">
<tr align="center" valign="middle">
<td><span class="genmed">
<input type="button" class="submit" accesskey="b" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+b" name="addbbcode0" value=" B " style="font-weight:bold; width: 30px" ****="bbstyle(0)" onMouseOver="helpline('b')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="i" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+i" name="addbbcode2" value=" i " style="font-style:italic; width: 30px" ****="bbstyle(2)" onMouseOver="helpline('i')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="u" title="Paymimas tekstas ir pastausti į mygtuką, arba alt+u" name="addbbcode4" value=" u " style="text-decoration: underline; width: 30px" ****="bbstyle(4)" onMouseOver="helpline('u')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="q" name="addbbcode6" value="Citata" style="width: 60px" ****="bbstyle(6)" onMouseOver="helpline('q')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="p" name="addbbcode14" value="Img" style="width: 40px" ****="bbstyle(14)" onMouseOver="helpline('p')" />
</span></td>
<td><span class="genmed">
<input type="button" class="submit" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline; width: 40px" ****="bbstyle(16)" onMouseOver="helpline('w')" />
</span></td>
</tr>
<tr>
<td colspan="9">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Veideliai</td>
<td nowrap="nowrap" align="right"><span class="gensmall">[url=javascript:bbstyle(-1)]Udaryti tagus[/url]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="9"> <span class="gensmall">
<input type="text" name="helpbox" size="45" maxlength="100" style="width:450px; font-size:9px; background-color:#F4F5FA;" readonly class="input" value="Patarimas: Teksto formavimo stilius gali būti pritaikytas paymėtam tekstui" onMouseOver="helpline('s')" />
</span></td>
</tr>
<tr>
<td colspan="9"><span class="gen">
<textarea name="message" rows="15" cols="35" wrap="soft" style="width:450px" tabindex="3" class="input" onselect="storeCaret(this);" ****="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
</span></td>
</tr>
</table><input type="button" value="Ataukti" class="submit" ****="history.go(-1)"><input type="button" name="post" class="submit" value="Paiūrėti" ****="popup(); " /><input type="submit" name="post" class="submit" value="Įrayti" />
</form>[/code]