Submit to Perl CGI not passing values

P

Prince Al

Hi,

I am attempting to write a dynamic javascript page. There is a button
on the page that when clicked, calls a function that adds some hidden
fields to a form and then submits it. The submit appears to work fine
(i.e. it calls the CGI script), but the query string is empty, using
GET or POST methods. A cut down version of my code is:

function sub() {
var tables =
document.getElementById("outer").getElementsByTagName("table");
var form = document.getElementsByTagName('form')[0];

for (i=0; i<tables.length; i++) {
var columns=i;
var truncs=i;
var links=i;
var sorts=i;

form.appendChild(createTextBox("cols_"+i,columns));
form.appendChild(createTextBox("links_"+i,links));
form.appendChild(createTextBox("truncs_"+i,truncs));
form.appendChild(createTextBox("sorts_"+i,sorts));
}

form.submit();
}

My form definition is:

<form name="theForm" method="get" action="cgi-bin/
create_driver.pl">
</form>

The submit button is created dynamically and calls the sub function
correctly. The submit button is created as a child to theForm.

I am at a loss as to what the problem is. Ideas anyone?

If it helps, I can post the full script, but I am just a bit reluctant
to as it is rather long!

Thanks in advance.

Tim
 
M

Martin Honnen

Prince said:
The submit button is created dynamically and calls the sub function
correctly. The submit button is created as a child to theForm.

That does not make much sense to me, you have a submit button (<input
type="submit">?) that when clicked calls the sub function, why does the
sub function need to call the submit method of the form?
As for the problem, you will need to show us the code of createTextBox.
 
P

Prince Al

That does not make much sense to me, you have a submit button (<input
type="submit">?) that when clicked calls the sub function, why does the
sub function need to call the submit method of the form?
As for the problem, you will need to show us the code of createTextBox.

Hi Martin,

Thanks for your reply. The reason I have submit method is that I want
to "collate" the information the user has entered onto the page into a
form that will be easier for the CGI script to interpret. This is what
the sub() function does by putting the information into strings in the
text boxes. I have also tried it with the button being a regular
type="button" with the same result. The code you asked for is:

function createTextBox(id,value) {
var textbox = document.createElement("input");
textbox.setAttribute("id",id);
textbox.type = "text";
textbox.value = value;
textbox.size = "100";
return textbox;
}

Thanks again

Tim
 
P

Prince Al

Form elements without a name attribute don't get submitted to the
server. The setAttribute is buggy in IE, set the property directly. ISTR
that IE had a problem with dynamic form elements. Why not just hard code
the textbox, make it a hidden input, give it a name attribute, set its
value using the onsubmit event handler and let it get submitted?

Hi Randy,

That worked - thanks! Been bothering me for ages!

Many thanks

Tim
 

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

No members online now.

Forum statistics

Threads
474,157
Messages
2,570,879
Members
47,413
Latest member
KeiraLight

Latest Threads

Top