473,379 Members | 1,170 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,379 software developers and data experts.

Newb requires help with javascript submit

Hi.

I am trying to create a CGI script that will use Perl to read a text file to
get a list of values, then turn that list into a menu on a website. The menu
will be a form with a JavaScript "submit" function. . When someone selects a
menu-item, the form will submit the value of that list-entry to another CGI
page.

The problem I'm encountering is that the script I've written submits every
value of the form rather than the one specific menu item's value. This means
that, on the receiving CGI page, I'm unable to tell which one value has been
selected because I've received them all.

As near as I can tell, the flaw in my scripting is in the JS line (but just
in case I'm wrong, I've CC'd this to PERL.MISC).

I am very new to JS and am having a very difficult time comprehending it.
Before I display the code I've written, I'd like to also ask for
recommendations for good beginner-guide-books for JS. Is O'Reilly's "Rhino"
book a good starting place?

Regards and thanks.

Here's the relevant code:
print "<FORM ACTION='/cgi-bin/sub_cat_view.cgi' NAME='myform' METHOD=
'get' target='splash'>";
open (CATDAT, "<categories.dat");

while (<CATDAT>){
@categories = split /#/, "$_";
$cat_length = @categories;
$loop=0;
print "<H4>";

while ($loop < $cat_length){
print "<A
HREF='javascript:document.myform.submit()'>$catego ries
[$loop]</A><BR>";
print "<INPUT TYPE='hidden' NAME='$categories[$loop]'
VALUE='cat
egory'>";
$loop++;
}
}
close (CATDAT);
print "</FORM>";
Jul 23 '05 #1
4 1676
Lee
javascript_noob12 said:

Hi.

I am trying to create a CGI script that will use Perl to read a text file to
get a list of values, then turn that list into a menu on a website. The menu
will be a form with a JavaScript "submit" function. . When someone selects a
menu-item, the form will submit the value of that list-entry to another CGI
page.

The problem I'm encountering is that the script I've written submits every
value of the form rather than the one specific menu item's value. This means
that, on the receiving CGI page, I'm unable to tell which one value has been
selected because I've received them all.

As near as I can tell, the flaw in my scripting is in the JS line (but just
in case I'm wrong, I've CC'd this to PERL.MISC).


First, you need to learn HTML.
There is no way in HTML to submit only specific elements of a form.

You shouldn't really post CGI code to a Javascript group.
It's better to post a sample of HTML that demonstrates the problem.

One thing that you do need to know about Javascript is that it's
a bad idea to submit a form via the javascript: pseudo-protocol in
the HREF attribute of a link. If there's a reason to use links
instead of buttons, use the onclick handler, not the HREF attribute.

It seems like what you really want is a form with a single hidden
element whose value is set by Javascript before the form is submitted
when you click the link.

Jul 23 '05 #2
javascript_noob12 wrote:
As near as I can tell, the flaw in my scripting is in the JS line


You are probably right. But the code you posted is Perl.

What you should do, if you want an answer to your question, is post the
HTML/JavaScript that the Perl script produces to comp.lang.javascript.
Make sure you follow whatever posting guidelines comp.lang.javascript has.

Jul 23 '05 #3
javascript_noob12 wrote:
The problem I'm encountering is that the script I've written submits every
value of the form rather than the one specific menu item's value.


That's the way a submit button works.
You could modify your perl program to output many "<FORM ACTION=" lines
instead of just one.
-Joe
Jul 23 '05 #4
[posted & mailed]

On Mon, 6 Sep 2004, javascript_noob12 wrote:
The problem I'm encountering is that the script I've written submits
every value of the form rather than the one specific menu item's value.
This means that, on the receiving CGI page, I'm unable to tell which one
value has been selected because I've received them all. while ($loop < $cat_length){
print "<A
HREF='javascript:document.myform.submit()'>$categ ories
[$loop]</A><BR>";
print "<INPUT TYPE='hidden' NAME='$categories[$loop]'
VALUE='cat
egory'>";
$loop++;
}


As a Perl note, I'd suggest rewriting that as a for statement:

for my $cat (@categories) {
print qq{
<a href="javascript:document.myform.submit()">$cat</a><br>
<input type="hidden" name="$cat" value="category">
};
}

Your probably is half JS, half HTML. A form will submit *all* the data in
it. You either need to make a separate form for EACH link (which I do NOT
suggest), or else come up with a new mechanism for submitting the
appropriate data.

I don't understand why you make the *name* of the field to be passed
variable, and the value constant. Here's how I'd do it:

print qq{
<form method="..." action="something.cgi" name="myform">
<input type="hidden" name="cat" value="">
};

for my $cat (@categories) {
print qq{
<a href="javascript:document.myform.cat.value='$cat';
document.myform.submit()">$cat</a><br>
};
}

Now, when you click on a link, it sets the value of the 'cat' hidden
field, and then submits the form.

I'm not sure why you *need* a form, when you can just make links like

<a href="something.cgi?cat=$cat">$cat</a>

but maybe there's more you're not telling us.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
Senior Dean, Fall 2004 % have long ago been overpaid?
RPI Corporation Secretary %
http://japhy.perlmonk.org/ % -- Meister Eckhart
Jul 23 '05 #5

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

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
6
by: Shaun Fleming | last post by:
I've been trying to make this simple script compatible across various browsers. It works for IE 6.0 and NS 7 but doesnt work with Opera (I have version 7.11). This is what is supposed to happen:...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
11
by: Brian D | last post by:
I have been searching for a while to find an answer to this and I must be searching on the wrong keywords. Below is a snippet of my form. There are other form items on it, but I need to submit...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
21
by: Martin Eyles | last post by:
I am trying to get javascript to cause a page to post back. I have tried calling _doPostBack from my script, but generates an error "object expected". I think this is because the page's script...
2
by: Eric | last post by:
I have a textbox on a form that is populated from the database when the form loads. When I check textbox.Text when the user clicks my submit button, the value is always what it was when the form...
5
by: Rabel | last post by:
I am a flash designer so I dont know a whole lot about the javascript submit buttons (I may not even be describing it right sorry) but here is the code I am using. <IMG name="Checkout"...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
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
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.