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

Pass form name and value to a function

Sen
This is the Javascript function:
function auto_submit(form_name, value) {
document.form_name.elements[value].click();
}

This is the XHTML:
<select name="category" onchange="auto_submit(this.form.name,'Select')">

So, when choosing an option from the select list, the Select button is
clicked and the form is submitted. Somehow the function only works when
I replace form_name variable with the name of the form. Ex.
document.keychain_selector.elements[value].click();

How can this be solved?

Jul 23 '05 #1
4 18901
On Fri, 26 Nov 2004 14:45:43 +0100, Sen <me@privacy.net> wrote:
This is the Javascript function:
function auto_submit(form_name, value) {
document.form_name.elements[value].click();
}

This is the XHTML:
<select name="category"
onchange="auto_submit(this.form.name,'Select')">
[snip]
How can this be solved?


By passing a reference, not the name:

function auto_submit(form, elem) {
form.elements[elem].click();
}

<select ... onchange="auto_submit(this.form, 'Select');">

However, I'd like to point out that performing an action based upon
selection from a SELECT element is generally a bad idea. It's usually much
better to allow the user to perform the action themselves with a button.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
On Fri, 26 Nov 2004 14:45:43 +0100, Sen wrote:
This is the Javascript function: function auto_submit(form_name, value) {
document.form_name.elements[value].click();
}
form_name is a string, like your "value" variable, not a form's reference.
So:
document.forms[form_name].elements[value].click();

But you can directly use a reference to form:

<select name="category" onchange="auto_submit(this.form,'Select')">

function auto_submit(f, value) {
f.elements[value].click();
}

or a reference to button:

<select name="category" onchange="auto_submit(this.form.Select)">

function auto_submit(btn) {
btn.click();
}

or:

<select name="category" onchange="this.form.Select.click()">
So, when choosing an option from the select list, the Select button is
clicked and the form is submitted.


But why you don't use the submit method of form object?

<select name="category" onchange="this.form.submit()">

--
ZER0://coder.gfxer.web-designer/

~ Alcune persone sono ancora vive per il semplice motivo che e'
illegale ucciderle.

Jul 23 '05 #3
Sen
On 2004-11-26 15:19:31 +0100, "Michael Winter"
<M.******@blueyonder.co.invalid> said:
By passing a reference, not the name:

function auto_submit(form, elem) {
form.elements[elem].click();
}

<select ... onchange="auto_submit(this.form, 'Select');">
Thanks! That worked perfectly :)
However, I'd like to point out that performing an action based upon
selection from a SELECT element is generally a bad idea. It's usually
much better to allow the user to perform the action themselves with a
button.


I fully agree useability & standards wise but the form isn't made for a
wide audience. It's a keychain web app to store my passwords . I can
work a little speedier with this solution.

Jul 23 '05 #4
Sen
On 2004-11-26 15:28:33 +0100, ZER0 <ze********@libero.it> said:
form_name is a string, like your "value" variable, not a form's reference.
So: [...] or a reference to button: [...] or: [...]
All solution work perfectly :) but I prefer the shortest one.
But why you don't use the submit method of form object?
<select name="category" onchange="this.form.submit()">


Because I have three submit buttons with different values. Form.submit
doesn't send any value to the cgi.

Jul 23 '05 #5

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

Similar topics

0
by: Matt | last post by:
My problem is to allow ASP to interact with JSP, and I pass JavaScript object in my approach, but I wonder if it will work in network, not just in local machine. For testing purposes, the...
2
by: Mark | last post by:
Hi - I have a dynamically created table, which has a number of forms - each named consecutively as 'adduserX' where X is a number generated from ASP. Within each form, I need to have a button...
4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
3
by: Shippy | last post by:
Please help, this is doing my head in!!!! I am sure it is something really simple and ovbious that I am missing but for the life of me I cant find where!!! I have this function... <script>...
1
by: praveenit | last post by:
hi, I am writing a small java script code where , when the textbox is clicked a pop up window is opened . on entering some data in the text area present in pop up window and pressing ''save"...
1
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.