473,729 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.cg i' NAME='myform' METHOD=
'get' target='splash' >";
open (CATDAT, "<categories.da t");

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

while ($loop < $cat_length){
print "<A
HREF='javascrip t:document.myfo rm.submit()'>$c ategories
[$loop]</A><BR>";
print "<INPUT TYPE='hidden' NAME='$categori es[$loop]'
VALUE='cat
egory'>";
$loop++;
}
}
close (CATDAT);
print "</FORM>";
Jul 23 '05 #1
4 1696
Lee
javascript_noob 12 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_noob 12 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.javas cript.
Make sure you follow whatever posting guidelines comp.lang.javas cript has.

Jul 23 '05 #3
javascript_noob 12 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_noob 12 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='javascri pt:document.myf orm.submit()'>$ categories
[$loop]</A><BR>";
print "<INPUT TYPE='hidden' NAME='$categori es[$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="javascrip t:document.myfo rm.submit()">$c at</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="somethi ng.cgi" name="myform">
<input type="hidden" name="cat" value="">
};

for my $cat (@categories) {
print qq{
<a href="javascrip t:document.myfo rm.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
2129
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
6
2726
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: when the user clicks a button in the main window, a dialog window pops up. In the dialog the user enters a university to search for. When the string is submitted, the dialog then shows all the matches found in the database. The user picks one and...
3
1829
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
11
3005
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 a different value based on the image that is clicked. Lets say the name is "image" and the value is . How do I submit this with javascript? <form name="form1" method="post" action="launch.asp">
8
2578
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 courses are populated. When course is selected, lists of occurrences, groups and
21
24460
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 doesn't contain the method _doPostBack, which needs to be added by asp.net. How can I make asp.net add this script? Thanks, ME --
2
1487
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 loaded, no matter of what the user changed the text to. Any suggestions? protected void Page_Load(object sender, EventArgs e) { DataSet ds = Customers.GetCustomer(Request); if (ds.Tables.Rows.Count == 0) return;
5
2829
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" value="Checkout" SRC="imagesButtons/ purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/ purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/ purchaseButton_r2_c2.jpg'" onClick="JavaScript:document.forms.submit()">
5
13376
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8927
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8764
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9210
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9156
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.