form problem?

G

Geoff Cox

Hello,

How do I get the str_questions values into a form?! The following does
not work. I have also tried

document.write("<input type='hidden' name='slidervalues'
value=str_questions>");

Thanks

Geoff


document.getElementById("Slider1ValueText").innerHTML = str_questions;

document.write("<form
action='http://website/path/cgi-bin/formmail-nms.cgi'
method='post'>");
document.write("<input type='hidden' name='slidervalues'
value='str_questions'>");
document.write("<input type='hidden' name='recipient'
value='extraemails'>");
document.write("<input type='submit'send'>");
 
E

ExGuardianReader

Geoff said:
Hello,

How do I get the str_questions values into a form?! The following does
not work. I have also tried

document.write("<input type='hidden' name='slidervalues'
value=str_questions>");

Jaysus Geoff!? You're writing the *STRING" "str_questions", not
inserting the value of the *VARIABLE" str_questions! THINK ABOUT IT:

document.write("<input type='hidden' name='slidervalues' value='" +
str_questions + "'>");
 
G

Geoff Cox

document.write("<input type='hidden' name='slidervalues' value='" +
str_questions + "'>");

Thanks! I knew it was wrong but couldn't see how to get it right.
Working OK now but a second question - hwo do I create the <form ....
</form> without using document.write() which opens a new window? I
imagine it has to do with using a <SPAN element and
document.getElementById("myID").innerHTML but not clear how to do
it...

document.write("<form action ='http://website/path/formmail-nms.cgi'
method='post'>");
document.write("<input type ='hidden' name ='slidervalues' value='" +
str_questions + "'>");
document.write("<input type ='hidden' name ='recipient' value
='extraemails'>");
document.write("<input type ='submit' value='send'
onlick-'sendslidervalues'>");
document.write("</form>");

Cheers

Geoff
 
R

RobG

Geoff said:
Thanks! I knew it was wrong but couldn't see how to get it right.
Working OK now but a second question - hwo do I create the <form ....
</form> without using document.write() which opens a new window? I
imagine it has to do with using a <SPAN element and
document.getElementById("myID").innerHTML but not clear how to do
it...

I have no idea what to make of the above, it all seems very confused.
There is a syntax error below, fixing that may help (or not...).

Some general tips:

- Manually wrap it at about 70 characters to stop automatic wrapping.
- Make sure code can be cut and pasted and works (or demonstrates the
failure) without futher effort.
- Block code properly so it is easy to read.
document.write("<form action ='http://website/path/formmail-nms.cgi'
method='post'>");
document.write("<input type ='hidden' name ='slidervalues' value='" +
str_questions + "'>");
document.write("<input type ='hidden' name ='recipient' value
='extraemails'>");
document.write("<input type ='submit' value='send'
onlick-'sendslidervalues'>");

The last line has a serious error with the onclick attribute, it makes
no sense at all. It seems to have a hyphen instead of an equals sign
and the value is the name of the form rather than script.

[...]
 
G

Geoff Cox

Rob,

Sorry if not clear and re the error - I have removed that onclick
event anyway.

I have a set of slider values in an array which I want to pass on to
the formmail-nms.cgi script so that they can be emailed to me.

I assumed that the way to do this is to create a form and have a
hidden field which will do this.

In fact the code (below) I showed does work but the submit button
appears in a new window whereas I would like it to appear in the same
window ... so it just this element that I am not sure about - how to
get the submit button in the original window?

Cheers

Geoff

document.write("<form action ='http://website/path/formmail-nms.cgi'
method='post'>");
document.write("<input type ='hidden' name ='slidervalues' value='"
+ str_questions +"'>");
document.write("<input type ='hidden' name ='recipient' value
='extraemails'>");
document.write("<input type ='submit' value='send'>");
document.write("</form>");
 
R

RobG

Geoff said:
Rob,

Sorry if not clear and re the error - I have removed that onclick
event anyway.

I have a set of slider values in an array which I want to pass on to
the formmail-nms.cgi script so that they can be emailed to me.

I assumed that the way to do this is to create a form and have a
hidden field which will do this.

In fact the code (below) I showed does work but the submit button
appears in a new window whereas I would like it to appear in the same
window ... so it just this element that I am not sure about - how to
get the submit button in the original window?

I can't say why it appears in a new window. Try writing the whole thing
with a single document.write, or you could put all the HTML into a
single string, then write that, or put it into an array and join it and
write it.

document.write(
"<form action='http://website/path/formmail-nms.cgi' method='post'>",
"<input type='hidden' name ='slidervalues' value='",
str_questions,
"'>",
"<input type='hidden' name='recipient' value='extraemails'>",
"<input type='submit' value='send'>",
"</form>"
);

or

var htmlString =
"<form action='http://website/path/formmail-nms.cgi'"
+ " method='post'><input type='hidden' name ='slidervalues'"
+ " value='" + str_questions + "'>"
+ "<input type='hidden' name='recipient' value='extraemails'>"
+ "<input type='submit' value='send'></form>"
document.write( htmlString );

or

var htmlArray = [
"<form action='http://website/path/formmail-nms.cgi'",
" method='post'><input type='hidden' name ='slidervalues'",
" value='" + str_questions + "'>",
"<input type='hidden' name='recipient' value='extraemails'>",
"<input type='submit' value='send'></form>"
];
document.write( htmlArray.join() );

The last way is probably the fastest as it avoids concatentation. All
should be faster than multiple calls to document.write (though perhaps
not noticeably so in this case) - over to you.

[...]
 
L

Lee

Geoff Cox said:
Rob,

Sorry if not clear and re the error - I have removed that onclick
event anyway.

I have a set of slider values in an array which I want to pass on to
the formmail-nms.cgi script so that they can be emailed to me.

I assumed that the way to do this is to create a form and have a
hidden field which will do this.

In fact the code (below) I showed does work but the submit button
appears in a new window whereas I would like it to appear in the same
window ... so it just this element that I am not sure about - how to
get the submit button in the original window?

Cheers

Geoff

document.write("<form action ='http://website/path/formmail-nms.cgi'
method='post'>");
document.write("<input type ='hidden' name ='slidervalues' value='"
+ str_questions +"'>");
document.write("<input type ='hidden' name ='recipient' value
='extraemails'>");
document.write("<input type ='submit' value='send'>");
document.write("</form>");


The first time you use document.write() after the page has
been displayed, you clear the current contents of the page
and begin writing a new one.

I don't believe you're getting a new window when you use
document.write(). You're really just getting a new page
in the same window, right? What makes you think that the
rest of the form fields, other than the submit button, are
appearing in the original page? They're hidden, after all.

It seems odd to me that you're trying to send a form that
contains only data that already exists in the page. Don't
you already know the contents of the str_question variable?
Are you actually trying to display the questions to the user,
and send the answers to the formmail script?
 
G

Geoff Cox

var htmlArray = [
"<form action='http://website/path/formmail-nms.cgi'",
" method='post'><input type='hidden' name ='slidervalues'",
" value='" + str_questions + "'>",
"<input type='hidden' name='recipient' value='extraemails'>",
"<input type='submit' value='send'></form>"
];
document.write( htmlArray.join() );

The last way is probably the fastest as it avoids concatentation. All
should be faster than multiple calls to document.write (though perhaps
not noticeably so in this case) - over to you.

Rob,

I have used your last suggestion above but I still get the submit
button appearing in a new window! Perhaps you can see why from the
whole code below? In fact also get 2 commas in front of the button?!

Cheers

Geoff

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

<html>
<HEAD>

<link rel=stylesheet href="slider.css" type="text/css">
<SCRIPT SRC="slider.js"></SCRIPT>

<SCRIPT>

var mySlider1 = new Slider( "Slider1" );
var count = 0;
var slider_value = new Array(8);

mySlider1.leftValue = -10;
mySlider1.rightValue = 10;
mySlider1.defaultValue = 0;
mySlider1.offsetX = 1;
mySlider1.offsetY = 1;
mySlider1.buttonWidth = 10;
mySlider1.maxSlide = 288;

mySlider1.onchange
="document.getElementById('Slider1ValueText').innerHTML
=''+this.getValue(0)";


var lhs_questions = new Array(8)
lhs_questions[0]="I would often be in this situation";
lhs_questions[1]="I would often talk to a group of friends";
lhs_questions[2]="I would not worry if I stuttered here";
lhs_questions[3]="If I were to stutter here I would know why";
lhs_questions[4]="I would stutter mildy here";
lhs_questions[5]="If I were to stutter here, my friends would not be
able to tell";
lhs_questions[6]="If I were to stutter here I would feel bad";
lhs_questions[7]="If I were to stutter here, my group of friends would
be understanding";

var rhs_questions = new Array(8)
rhs_questions[0]="I would hardly ever be in this situation";
rhs_questions[1]="I would hardly talk to a group of friends";
rhs_questions[2]="I would worry if I stuttered here";
rhs_questions[3]="If I were to stutter here I would not know why";
rhs_questions[4]="I would stutter severly here";
rhs_questions[5]="If I were to stutter here, my friends would be able
to tell";
rhs_questions[6]="If I were to stutter here I would feel good";
rhs_questions[7]="If I were to stutter here, my group of friends would
not be understanding";

function buildTable()
{

document.write("<center>");
document.write("<table border='0' width='100%'>");

document.write("<tr>");
document.write(" <td ID='lhs_question' width='30%' valign='top'
height='70'>" + this.lhs_questions[count] + "</td>");
document.write(" <td width='40%' align='center' valign='top'
height='70'>" + "<IMG SRC='sliderbg.gif' NAME='Slider1RailImg'
ID='Slider1RailImg'>" + "</td>");
document.write(" <td ID='rhs_question' width='30%' valign='top'
height='70'>" + this.rhs_questions[count] + "</td>");
document.write("</tr>");

document.write("<tr><td colspan='3' align='center' valign='top'
height='100'>");
document.write("<input type='button' name ='nextbutton' value='Next'
onclick='next_question(this)' />");
document.write("<SPAN class='invisible'
ID='Slider1ValueText'></SPAN>");
document.write("<SPAN ID='Status'></SPAN></td></tr>");

document.write("</table>");
document.write("</center>");
}

function next_question(button)
{
slider_value[count] = this.mySlider1.getValue(0);
this.count++;
if (this.count < 8)
{
document.getElementById('lhs_question').innerHTML =
this.lhs_questions[count];
document.getElementById('rhs_question').innerHTML =
this.rhs_questions[count];

mySlider1.setValue( (mySlider1.leftValue + mySlider1.rightValue) / 2
);

} else
{
if (button.parentNode &&
button.parentNode.removeChild) {
button.parentNode.removeChild(button);

}
saveIt();
}
}

function saveIt()
{
var str_questions = "";
for (var i=0; i < slider_value.length; i++)
{
str_questions += slider_value + "\n";
}

document.getElementById("Slider1ValueText").innerHTML =
str_questions;

var htmlArray = [
"<form action='http://wwebsite/path/formmail-nms.cgi'",
" method='post'><input type='hidden' name ='slidervalues'",
" value='" + str_questions + "'>",
"<input type='hidden' name='recipient' value='extraemails'>",
"<input type='submit' value='send'></form>"
];

document.write( htmlArray.join() );

}

</script>


</HEAD>

<BODY onLoad="mySlider1.placeSlider()">

<h2 align="center">Social Group</h2>

<p align="center"><img src="pic3.jpg"></p>

<script language="javascript"
type="text/javascript">buildTable();</script>

<SCRIPT>

mySlider1.writeSlider();

</SCRIPT>

</body>
</html>













 
G

Geoff Cox

The first time you use document.write() after the page has
been displayed, you clear the current contents of the page
and begin writing a new one.
I don't believe you're getting a new window when you use
document.write(). You're really just getting a new page
in the same window, right? What makes you think that the
rest of the form fields, other than the submit button, are
appearing in the original page? They're hidden, after all.

Lee,

Ah! You are quite correct - I should have been saying new page not
new window. Thanks for that.
It seems odd to me that you're trying to send a form that
contains only data that already exists in the page. Don't
you already know the contents of the str_question variable?
Are you actually trying to display the questions to the user,
and send the answers to the formmail script?

I do indeed know the contents of the str_question variable - I just
want to pass the contents to the formmail-nms.cgi script which will
send these values to me via email. Hence the wish to put these
contents into a hidden field in a form.

In actual fact I have script that works fine using prototype.js but am
trying to get this to work with a simple <form> as prototype.js seems
overkill for what I am trying to do...!

Cheers

Geoff
 
G

Geoff Cox

Apologies Rob - I should have been saying a new page not a new window
- this has just been pointed out to me by Lee. Stupid mistake.

Geoff
 
A

ASM

Geoff said:
I have used your last suggestion above but I still get the submit
button appearing in a new window!

Isn't it because you forgot to display the div "Slider1ValueText"
somewhere on your page ? !

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> [...]
<BODY onLoad="mySlider1.placeSlider()">

<h2 align="center">Social Group</h2>

<p align="center"><img src="pic3.jpg"></p>

<script language="javascript"
type="text/javascript">buildTable();</script>
 
G

Geoff Cox

Isn't it because you forgot to display the div "Slider1ValueText"
somewhere on your page ? !

Stephane,

Too true!

The code below now works OK in that the send button appears on the
same page but

1. there are 2 commas in front of it - can you see where they come
from?

2. is it possible to have the form sent without the user having to
click on the send button?

Thanks

Geoff

function saveIt()
{

var str_questions = "";
for (var i=0; i < slider_value.length; i++)
{
str_questions += slider_value + "\n";
}

document.getElementById("Slider1ValueText").innerHTML =
str_questions;

var htmlArray = [
"<form action='http://website/path/formmail-nms.cgi'",
" method='post'><input type='hidden' name ='slidervalues'",
" value='" + str_questions + "'>",
"<input type='hidden' name='recipient' value='extraemails'>",
"<input type='submit' value='send'></form>"
];

// document.write( htmlArray.join() );

document.getElementById("form").innerHTML = htmlArray.join();

}

</script>


</HEAD>

<BODY onLoad="mySlider1.placeSlider()">

<h2 align="center">Social Group</h2>

<p align="center"><img src="pic3.jpg"></p>

<script language="javascript"
type="text/javascript">buildTable();</script>

<div id="form"></div>

<SCRIPT>

mySlider1.writeSlider();

</SCRIPT>

</body>
</html>
 
A

ASM

Geoff said:
Too true!

The code below now works OK in that the send button appears on the
same page but

1. there are 2 commas in front of it - can you see where they come
from?

I've seen that and ... my little finger didn't tell it to my ear

Change your code ... ?
2. is it possible to have the form sent without the user having to
click on the send button?

of course !
function saveIt()
{

var str_questions = "";
for (var i=0; i < slider_value.length; i++)
{
str_questions += slider_value + "\n";
}

document.getElementById("Slider1ValueText").innerHTML =
str_questions;


var htmlArray =
"<form action='http://website/path/formmail-nms.cgi'"+
" method='post'><input type='hidden' name ='slidervalues'"+
" value='" + escape(str_questions) + "'>"+
"<input type='hidden' name='recipient' value='extraemails'>"+
"<input type='submit' value='send'></form>";

document.getElementById("form").innerHTML = htmlArray;

var subForm = document.getElementById("form");
subForm = document.getElementsByTagName('FORM')[0];
subForm.submit();
 
A

ASM

ASM said:
function saveIt(){
var str_questions = "";
for (var i=0; i < slider_value.length; i++) {
str_questions += slider_value + "\n";
}
document.getElementById("Slider1ValueText").innerHTML=str_questions;


var htmlArray =
"<form action='http://website/path/formmail-nms.cgi'"+
" method='post'><input type='hidden' name ='slidervalues'"+
" value='" + escape(str_questions) + "'>"+
"<input type='hidden' name='recipient' value='extraemails'>"+
"<input type='submit' value='send'></form>";

document.getElementById("form").innerHTML = htmlArray;


var subForm = document.getElementById("form");
subForm = subForm.getElementsByTagName('FORM')[0];
subForm.submit();
}
 
R

Richard Cornford

Geoff Cox wrote:
1. there are 2 commas in front of it - can you see where
they come from?
// document.write( htmlArray.join() );
<snip>

The commas a caused by your not passing a string argument to the
Array's - join - method. The default string used by
Array.prototype.join - is ",", and the output is the same of the
Array's - toString - method. You should pass an empty string to the
Array's join method so that is the string inserted between non-undefined
array elements when - join - builds the string. E.G.:-

document.write( htmlArray.join('') );

Richard.
 
G

Geoff Cox

I dont get it !!! If you know the contents - why do you need it emailed to
you ??

Zoe,

I see what you mean! The questions are to be answered by other people
and their results are sent to me by email ... so although I know the
slider values at the moment, I will not know then later!

Cheers

Geoff
 
G

Geoff Cox

Geoff Cox wrote:


<snip>

The commas a caused by your not passing a string argument to the
Array's - join - method. The default string used by
Array.prototype.join - is ",", and the output is the same of the
Array's - toString - method. You should pass an empty string to the
Array's join method so that is the string inserted between non-undefined
array elements when - join - builds the string. E.G.:-

document.write( htmlArray.join('') );

Thanks Richard - the ,, have gone.

Cheers

Geoff
 
G

Geoff Cox

var htmlArray =
"<form action='http://website/path/formmail-nms.cgi'"+
" method='post'><input type='hidden' name ='slidervalues'"+
" value='" + escape(str_questions) + "'>"+
"<input type='hidden' name='recipient' value='extraemails'>"+
"<input type='submit' value='send'></form>";

document.getElementById("form").innerHTML = htmlArray;

var subForm = document.getElementById("form");
subForm = document.getElementsByTagName('FORM')[0];
subForm.submit();

Stephanie,

That does the trick but could you explain how it works?!

Thanks

Geoff
 
A

ASM

Geoff said:
var htmlArray =
"<form action='http://website/path/formmail-nms.cgi'"+
" method='post'><input type='hidden' name ='slidervalues'"+
" value='" + escape(str_questions) + "'>"+
"<input type='hidden' name='recipient' value='extraemails'>"+
"<input type='submit' value='send'></form>";

document.getElementById("form").innerHTML = htmlArray;

var subForm = document.getElementById("form");
subForm = document.getElementsByTagName('FORM')[0];
subForm.submit();


Stephanie,

Geoff,
it's Stephane, thanks
That does the trick but could you explain how it works?!

what don't you understand ?

'htmlArray' here is a variable and no more an array
its value is a string built with 2 others strings and your variable
'str_questions' created further above

example :
(I have to tronckate strings because
lines on a post are limited to 72 letters long)

var txt_1 = '<form action="http://website/path/formmail-nms.cgi" '+
'method="post"><input type="hidden" name="slidervalues" value="';
vr txt_2 = '"><input type="hidden" name="recipient"' +
' value="extraemails"><input type="submit" value="send"><\/form>';

var htmlArray = text_1 + escape(str_questions) +text_2;

escape() to get a traduction for url

then ...
document.getElementById("form").innerHTML = htmlArray;
you did understand

a shortcut for the div 'form'
var subForm = document.getElementById("form");

let's change this shortcut, now for the form inside precedent div 'form'
subForm = subForm.getElementsByTagName('FORM')[0];
(1st element of forms collection found in div 'form')

shortcut of our form now receives order to submit :
subForm.submit();
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top