473,320 Members | 2,071 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,320 software developers and data experts.

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="update( "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.selectedIndex;
selected_value = document.forms.formName.selName[selectedIndex];
}

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

selected_index = document.forms.myForm.selectedIndex;
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 2497
<pa**@paullee.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.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="update( "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.selectedIndex;
selected_value = document.forms.formName.selName[selectedIndex];
}


Some variant of the following would work.

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

function dochange(elt)
{
alert(elt.value);
}
Jul 23 '05 #2
pa**@paullee.com 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="update( "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.selectedIndex;
selected_value = document.forms.formName.selName[selectedIndex];
}

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

selected_index = document.forms.myForm.selectedIndex;
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.options[selectElement.selectedIndex]
var selectValue = selectIndex.value;
}

--
Randy
comp.lang.javascript 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(formName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.options[selectElement.selectedIndex];
var selectValue = selectIndex.value;

alert(selectValue);

}
</script>
<form action="ViewAllocation.php" name="myForm">
<select name="mySel" onChange="updateStuff(myForm,mySel)">
<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.javascript:
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.com 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(formName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.options[selectElement.selectedIndex];
var selectValue = selectIndex.value;

alert(selectValue);

}
</script>
<form action="ViewAllocation.php" name="myForm">
<select name="mySel" onChange="updateStuff(myForm,mySel)">


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

onChange="updateStuff('myForm','mySel')"

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

[snip]

Mick
Jul 23 '05 #6
pa**@paullee.com 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(formName,selName)
{
var frm = document.forms[formName];
var selectElement = frm.elements[selName]; <!-- error here -->
var selectIndex = selectElement.options[selectElement.selectedIndex];
var selectValue = selectIndex.value;

alert(selectValue);

}
</script>
<form action="ViewAllocation.php" name="myForm">
<select name="mySel" onChange="updateStuff(myForm,mySel)">
onChange="updateStuff('myForm','mySel')"

or:

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

function updateStuff(formRef,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.javascript 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
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...
2
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...
4
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...
1
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...
4
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...
5
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...
8
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 &...
10
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.