473,378 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Submit One Field of a Form to a New Window

Hello,
I have an html form which users fill out and submit. The form contains
one textarea which I want them to preview before submitting. This,
probably, means that there will be a link/button saying "Preview" and
JS will open a new window and submit the form. The new window page
will get value of one field and display it. I believe this is how it
should be done.

Is there a good way someone can recommend me how I can implement this
or suggest a better way, perhaps.

Thank you

Mar 1 '07 #1
6 1955
ASM
vu******@gmail.com a écrit :
Hello,
I have an html form which users fill out and submit. The form contains
one textarea which I want them to preview before submitting. This,
probably, means that there will be a link/button saying "Preview" and
JS will open a new window and submit the form. The new window page
will get value of one field and display it. I believe this is how it
should be done.

Is there a good way someone can recommend me how I can implement this
or suggest a better way, perhaps.
I do not understand why a field value has to be shown in a popup ...

<html>
<style type="text/css">
#agree { display: none; }
</style>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
function agree() {
if($('agree').style.display!='block') {
alert('please use the button to send the form');
return false;
}
return true;
}
</script>
<form onsubmit="return agree()" action="test.htm" >
<div id="agree">
<textareasome text to read </textarea><br>
<input type=reset value="disagree"
onclick="$('agree').style.display='none';">
<input type=submit value="I agree"
onclick="agrement.value='ok';">
<input type=hidden name="agrement" value="no">
</div>
<p>nom <input name=nom>
<p>prenom <input name=prenom>

<p><input type=button value="Send"
onclick="$('agree').style.display='block';location ='#agree';">
</form>
</html>
If JS is disabled nothing will work ...

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 2 '07 #2
On Mar 1, 8:25 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
vunet...@gmail.com a écrit :
Hello,
I have an html form which users fill out and submit. The form contains
one textarea which I want them to preview before submitting. This,
probably, means that there will be a link/button saying "Preview" and
JS will open a new window and submit the form. The new window page
will get value of one field and display it. I believe this is how it
should be done.
Is there a good way someone can recommend me how I can implement this
or suggest a better way, perhaps.

I do not understand why a field value has to be shown in a popup ...

<html>
<style type="text/css">
#agree { display: none; }
</style>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
function agree() {
if($('agree').style.display!='block') {
alert('please use the button to send the form');
return false;
}
return true;}

</script>
<form onsubmit="return agree()" action="test.htm" >
<div id="agree">
<textareasome text to read </textarea><br>
<input type=reset value="disagree"
onclick="$('agree').style.display='none';">
<input type=submit value="I agree"
onclick="agrement.value='ok';">
<input type=hidden name="agrement" value="no">
</div>
<p>nom <input name=nom>
<p>prenom <input name=prenom>

<p><input type=button value="Send"
onclick="$('agree').style.display='block';location ='#agree';">
</form>
</html>

If JS is disabled nothing will work ...

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Oh, it's very easy: I have a textfield where user writes the
description of the item. It can be a long text value or html. Then I
want them to preview how it will look like on the page before they
submit it. So, I just want a new window to be open with that field
info inside. Your example shows a bit different solution. Thanks for
your time and help.

Mar 2 '07 #3
ASM
vu******@gmail.com a écrit :
So, I just want a new window to be open with that field
info inside. Your example shows a bit different solution. Thanks for
your time and help.
<html>
<style type="text/css">
#viewer { position:absolute;top:20px;border:2px solid #888;
width:90%;left:5%;height:300px;overflow:auto;
padding:8px;background:white;display:none;cursor:p ointer }
</style>
<script type="text/javascript">

function preview() {
var t = document.forms[0].userText.value;
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';
}
</script>
<form>
<textarea name="userText" style="width:80%;height:200px"></textarea>
<input value="Preview" onclick="preview();" type=button>
</form>

blah

<div id="viewer" onclick="this.style.display='none';"></div>
</html>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 2 '07 #4
On Mar 2, 12:33 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
vunet...@gmail.com a écrit :
So, I just want a new window to be open with that field
info inside. Your example shows a bit different solution. Thanks for
your time and help.

<html>
<style type="text/css">
#viewer { position:absolute;top:20px;border:2px solid #888;
width:90%;left:5%;height:300px;overflow:auto;
padding:8px;background:white;display:none;cursor:p ointer }
</style>
<script type="text/javascript">

function preview() {
var t = document.forms[0].userText.value;
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';}

</script>
<form>
<textarea name="userText" style="width:80%;height:200px"></textarea>
<input value="Preview" onclick="preview();" type=button>
</form>

blah

<div id="viewer" onclick="this.style.display='none';"></div>
</html>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
and that would be a good solution indeed, if not something to
consider:
I cannot control wheather user enters text or html. if html is
entered, then would I really have to check for every possible html
tag, such as <br>, <table>, etc. to preserve plain text line breaks?

For example, If user enters:
-this
-is
-example
then the JS innnerHTML shows "-this -is -example", so I need to
convert line breaks to <br>.
But if user types "-this <br>-is <br>-example", there will be a break
with innerHTML.
What if situation is somehow different than this? Do i need to
consider every case or it would be just more simple to send it to
another popup window and display it the way it would really look no
matter what...?

Mar 2 '07 #5
ASM
vu******@gmail.com a écrit :
I cannot control wheather user enters text or html. if html is
entered, then would I really have to check for every possible html
tag, such as <br>, <table>, etc. to preserve plain text line breaks?

For example, If user enters:
-this
-is
-example
then the JS innnerHTML shows "-this -is -example", so I need to
convert line breaks to <br>.
But if user types "-this <br>-is <br>-example", there will be a break
with innerHTML.
What if situation is somehow different than this? Do i need to
consider every case or it would be just more simple to send it to
another popup window and display it the way it would really look no
matter what...?
you'll have same problems in a new window(*) or in a div in main window.

You asked about text entered as html (with tags and so on)
and that works fine in my test.

Now if you want to display in html some "normal" text it is not same song.
You can try :

function preview() {
var t = document.forms[0].userText.value;
if(t.indexOf('<')<0) t = '<pre>'+t+'<\/pre>';
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';
}

But probably you'll prefer :

function preview() {
var t = document.forms[0].userText.value;
t = t.replace(/>(\n|\r)/g,'>').replace(/\n|\r/g,'<br>');
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';
}

(*) about the option "opening in a new window", test that :

<html>
<script type="text/javascript">
function preview() {
truc = window.open('','','width=300,height=300');
truc.document.open();
truc.document.write(document.forms[0].userText.value);
truc.document.close();
}
</script>
<form>
<textarea name="userText" style="width:80%;height:200px">
<div style="background:yellow">
<h1>test</h1>
<p>to see
</div>

an now,
with some
return carriages
</textarea>
<input value="Preview" onclick="preview();" type=button>
</form>
</html>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 2 '07 #6
On Mar 2, 6:01 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
vunet...@gmail.com a écrit :
I cannot control wheather user enters text or html. if html is
entered, then would I really have to check for every possible html
tag, such as <br>, <table>, etc. to preserve plain text line breaks?
For example, If user enters:
-this
-is
-example
then the JS innnerHTML shows "-this -is -example", so I need to
convert line breaks to <br>.
But if user types "-this <br>-is <br>-example", there will be a break
with innerHTML.
What if situation is somehow different than this? Do i need to
consider every case or it would be just more simple to send it to
another popup window and display it the way it would really look no
matter what...?

you'll have same problems in a new window(*) or in a div in main window.

You asked about text entered as html (with tags and so on)
and that works fine in my test.

Now if you want to display in html some "normal" text it is not same song.
You can try :

function preview() {
var t = document.forms[0].userText.value;
if(t.indexOf('<')<0) t = '<pre>'+t+'<\/pre>';
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';

}

But probably you'll prefer :

function preview() {
var t = document.forms[0].userText.value;
t = t.replace(/>(\n|\r)/g,'>').replace(/\n|\r/g,'<br>');
var v = document.getElementById('viewer');
v.innerHTML = t;
v.style.display = 'block';

}

(*) about the option "opening in a new window", test that :

<html>
<script type="text/javascript">
function preview() {
truc = window.open('','','width=300,height=300');
truc.document.open();
truc.document.write(document.forms[0].userText.value);
truc.document.close();}

</script>
<form>
<textarea name="userText" style="width:80%;height:200px">
<div style="background:yellow">
<h1>test</h1>
<p>to see
</div>

an now,
with some
return carriages
</textarea>
<input value="Preview" onclick="preview();" type=button>
</form>
</html>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
thank you, that's really helpful

Mar 5 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Piotr | last post by:
I have popup window (window.open) where I put any value in input field. After submit I wan to to return to the main window and get value from popup window. How to close popup window and return to...
4
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
3
by: Anthony | last post by:
I have a form on a web page that requires to click on a button to submit the information. I have two questions about changing this form: 1. Is there a way that I can change the script so that the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.