473,806 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting form details with a function

Hi all,
Is there a way to access a forms details by sending its parameters to a
function. For example, I have a form
named "myForm" populated by a drop down box, so that <select
name="mySel">

I am trying to send the form and drop down box name to a javascript
function, eg onChange="updat e( "myForm", "mySel")
so that, within the Javascript update(formName , selName) function
I can access the forms doing something like this:

update(formName , selName)
{
selected_index = document.forms. formName.select edIndex;
selected_value = document.forms. formName.selNam e[selectedIndex];
}

so that I can access the specified value using the input arguments to
the function, rather than doing

selected_index = document.forms. myForm.selected Index;
selected_value = document.forms. myFormn.mySel[selectedIndex];

The reason for this is because I have a lot of drop box boxes that are
changed by the user.

Thanks in advance

Paul
--
http://www.paullee.com

Jul 23 '05 #1
6 2525
<pa**@paullee.c om> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
Hi all,
Is there a way to access a forms details by sending its parameters to a
function. For example, I have a form
named "myForm" populated by a drop down box, so that <select
name="mySel">

I am trying to send the form and drop down box name to a javascript
function, eg onChange="updat e( "myForm", "mySel")
so that, within the Javascript update(formName , selName) function
I can access the forms doing something like this:

update(formName , selName)
{
selected_index = document.forms. formName.select edIndex;
selected_value = document.forms. formName.selNam e[selectedIndex];
}


Some variant of the following would work.

<select name=fred onchange="docha nge(this)">
<option value="bob">Bob
<option value="jim">Jim
</select>

function dochange(elt)
{
alert(elt.value );
}
Jul 23 '05 #2
pa**@paullee.co m wrote:
Hi all,
Is there a way to access a forms details by sending its parameters to a
function. For example, I have a form
named "myForm" populated by a drop down box, so that <select
name="mySel">

I am trying to send the form and drop down box name to a javascript
function, eg onChange="updat e( "myForm", "mySel")
so that, within the Javascript update(formName , selName) function
I can access the forms doing something like this:

update(formName , selName)
{
selected_index = document.forms. formName.select edIndex;
selected_value = document.forms. formName.selNam e[selectedIndex];
}

so that I can access the specified value using the input arguments to
the function, rather than doing

selected_index = document.forms. myForm.selected Index;
That one won't give you what you are after unless the form is named
forms and the select is named myForm
selected_value = document.forms. myFormn.mySel[selectedIndex];
The reason for this is because I have a lot of drop box boxes that are
changed by the user.


You start with this groups FAQ, and some of its notes.

http://jibbering.com/faq/#FAQ4_13

function update(formName , selName){
var frm = document.forms[formName];
var selectElement = frm.elements[selName];
var selectIndex = selectElement.o ptions[selectElement.s electedIndex]
var selectValue = selectIndex.val ue;
}

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #3
Hi,
I read the FAQ and it answered some questions, but I am still having
some problems.

I've tried your suggestion, but I still get problems. My code is as
follows
(just for one drop-down box at the moment)

<script type="text/javascript">
function updateStuff(for mName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.o ptions[selectElement.s electedIndex];
var selectValue = selectIndex.val ue;

alert(selectVal ue);

}
</script>
<form action="ViewAll ocation.php" name="myForm">
<select name="mySel" onChange="updat eStuff(myForm,m ySel)">
<option value="abc">abc </option>
<option value="12">12</option>
<option value="18">18</option>
</select>
</form>

</BODY>
</HTML>

Basically, it gets to the indicated line and then I get an error
message saying " 'elements' is null or not an object "

TIA

Paul

Jul 23 '05 #4
wrote on 24 feb 2005 in comp.lang.javas cript:
I've tried your suggestion


This is NOT email, but Usenet.

Please quote where you're responding on, or
email your response privatly to the one you are calling "you".
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5
pa**@paullee.co m wrote:
Hi,
I read the FAQ and it answered some questions, but I am still having
some problems.

I've tried your suggestion, but I still get problems. My code is as
follows
(just for one drop-down box at the moment)

<script type="text/javascript">
function updateStuff(for mName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.o ptions[selectElement.s electedIndex];
var selectValue = selectIndex.val ue;

alert(selectVal ue);

}
</script>
<form action="ViewAll ocation.php" name="myForm">
<select name="mySel" onChange="updat eStuff(myForm,m ySel)">


You need to pass form name and select name to the updateStuff function,
which are strings.

onChange="updat eStuff('myForm' ,'mySel')"

I don't see any value in what you're doing, though.

[snip]

Mick
Jul 23 '05 #6
pa**@paullee.co m wrote:
Hi,
I read the FAQ and it answered some questions, but I am still having
some problems.
You missed part of it. It talks of quoting what you are replying to so
that the people who read it know what you are referring to.
I've tried your suggestion, but I still get problems. My code is as
follows
(just for one drop-down box at the moment)

<script type="text/javascript">
function updateStuff(for mName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.o ptions[selectElement.s electedIndex];
var selectValue = selectIndex.val ue;

alert(selectVal ue);

}
</script>
<form action="ViewAll ocation.php" name="myForm">
<select name="mySel" onChange="updat eStuff(myForm,m ySel)">
onChange="updat eStuff('myForm' ,'mySel')"

or:

onChange="updat eStuff(this.for m,this)"
I prefer the second but it changes your function a little bit. With the
above, it would become something like this:

function updateStuff(for mRef,selRef){
//No need to define frm, you have a reference
//to it already in formRef. Same goes for selectIndex
//It is passed as selRef. What you end up with is this:

var selectValue = selName.value;
}
<option value="abc">abc </option>
<option value="12">12</option>
<option value="18">18</option>
</select>
</form>

</BODY>
</HTML>

Basically, it gets to the indicated line and then I get an error
message saying " 'elements' is null or not an object "


See Above.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #7

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

Similar topics

2
1396
by: John M | last post by:
Hi, I have a continuous form which shows a record on each line. Further details are available by clicking on a box which runs code to open a further form to give more details of the record. It works well. BUT you could well have your cursor on one record and click on the box for extra details of another. The result is that the details of the wrong record are displayed. To find the right record I'm using
2
2359
by: Chad | last post by:
In our application, I would like to send out HTML mail. TO do so, I must do something like this: Mail.Body = <raw HTMLTEXT String> Hence, I would like to know how to get the HTML text for Web Controls. You'll notice below in lines 33-37 that that code does correctlt return the HTML for a textbox. How do I make it generic so it returns the HTML for any control. Hopefully, if the control is a container control, it will return the HTML for...
4
3524
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 click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
1
3203
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows: The code below is for the first page:session_start is in line 3 <link href="css/jobSheet.css" rel="stylesheet" type="text/css" /> session_start();
4
6231
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for Struts: import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator;
5
2550
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but fails.... Any ideas??? <html> <head><title>New Details</title> </head> <center> <H2><IMG SRC="$(path)smlogo.gif"><br>
8
2437
by: glamster7 | last post by:
Ok folks its Friday & I'm feeling a bit thick (also not very well). I have a form Salonmanagerdetail wich allows the user to enter the following details Stylist_Id,Stylist_Name,Group_Name & SM_Dates. SM_Dates are the dates a stylist is designated Salon Manager for (This happens every x weeks). This data is stored in the table Salonmanagerdetail. Users can view this data via the View Stylist form which is a tabbed form with 3 tabs -...
10
1857
by: susan | last post by:
Hi, Is it (in Access2003) possible yo link from a form in db1 to a form in db2? Thanks, Susan
12
1914
by: Richard Penfold | last post by:
I am developing an order tracking database, which to keep this explanation simple, consists of 'Orders' table, 'Order Details' table, 'Deliveries' table & 'Inventory' table. There are one-to-many relationships from Orders to 'Order Details, Orders to Deliveries and Orders to Inventory. I have forms to enter and track customer orders and inventory transactions; these work fine but I am having difficulty getting a list-box control to work the...
0
9719
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
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10110
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
9187
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...
0
6877
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
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.