DOM: Form Array?
Apr 27, 2007Is there a window.opener.document.form[0]?
View 2 RepliesIs there a window.opener.document.form[0]?
View 2 RepliesI am working on a page where the user will select a location from a dynamically generated dropdown list. I was able to create the php multidimensional array (tested and working) from a MySql database using the users information at login, but I'm having problems converting it to a javascript multidimensional array. I need to be able to access variables that I can pass to a number of text fields within an html form.For instance, if a user belongs to a company with multiple addresses, I need to be able to let them select the address they need to prepopulate specific text fields.
View 9 Replies View RelatedI am creating an array based on form elements. I then am trying to create an IF (and nested IF) statement to check if the fields are empty and then with the nested IF statement use certain fields to create mathematical functions.
So far I have this:
function QuantityMWh(form) {
var formchk = document.forms[0]
for (i = 0; i < formchk.elements.length; i++) {
if (formchk.elements[1].value == "" && formchk.elements[2].value == "") {
[Code]....
It's only checking the first field and not the second, and vice versa. i.e. if only one field has text then it passes.
Lets say I have an empty array and I want the user to be able to enter as many new numbers as the user wants into the array. Could you explain how? Simply put it: How can javascript parse a textarea and input it into an array. (Like if the user entered 1 3 5 7 4).
<script>
function example(form){
var myNumbers=new Array();
then I'll do something with the array once the #'s are loaded...
[Code]....
I need to verify that the email address is not a free account. I will have an array that contains a list of free email providers. ie. gmail yahoo hotmail.I want to compare this list to what the user entered. and if there email address contains one of the values from the array then return false. I am a php dev so excuse the crude code.
Code:
var freeEmail=new Array("gmail","yahoo","hotmail");
if (form.email_address.value (contain a value from freeEmail) {
alert( "Please no free email accounts." );
[code]....
I am new to JavaScript and self taught, so please bear with any terminology I use incorrectly. I have an array defined. I am trying to access this array multiple times (10) in the HTML. It worked on the first drop down, but when I added the next one it errored. Not sure if what I am trying to do is possible or if I am going about this the right way. Below is the code:
Code:
var Engagements = [];
Engagements[0] = new Option("","");
Engagements[1] = new Option("Asset Management","Asset Management");
Engagements[2] = new Option("Autoclave","Autoclave");
[Code]...
Having a form like this:
HTML Code:
when I capture the dispatch of the form and try to get the value of any of these file fields:
PHP Code:
There's a Javascript error saying that form.file is undefined. It's strange because I see in Firebug that "file" actually exists as a property of "form". The same happens if I get rid of the temporary variable "form" and I do it this way:
So, I eventually had to use the getElementById('image' + i) method in order to do what I wanted. But there must be a "natural" way to get a value from an array defined in a form.
im fiddeling about with javascript and learning the basics. say you make a javascript array keeping it simple for just now, say the array had 5 items in it, how can you make it so the user has to input a number which selectes one of the objects from the array ? my friend told me to use a form but i dont know how i can link this to the javascript array.
[Code]...
I have a form that has an array of input values:
I do this so I can loop through the values in php... now...that's the easy part... the hard part comes to this:
Next to each of those boxes is a search button that allows the user to open up a popup window that they can search for an item, and select the item. Once they select the item it should populate that particular input box with the selected item. I can easily do this with a uniquely named input box, but can't seem to figure out how to do it with an array of input boxes...
I use a very handy function (onsubmit) to validate empty fields in a form:
PHP Code:
function validate_form(){
var x = document.getElementById("form1");
for(var i=0; i<x.length; i++){
if((x.elements[i].value == "") && (x.elements[i].title)){
[Code]....
It worked like a charm, until I had to change a dropdown dynamically with ajax. I have two dropdowns, the second being populated with ajax (php, mysql) by the option selected in the first one. The second dropdown has the title attribute filled so the previous function can validate and ask the user to select something. However, it seems like fields loaded dynamically with ajax wont appear inside the x.elements[] array. I've tested it over and over, it keeps ignoring it. It isn't even in the array. Why?
'm having a very hard time making this work and be happy in both IE and Firefox. Basically, I'm setting a timeout to get an array of the form values if not present, or compare against if they are present, and if any change in values, submit the form to auto-save it.
below is my coding, basically I am using document.forms[thisformname].elements - but that gives me a lot of things that are NOT form fields and I just need to read input:text, input:checkboxk, input:radio, textarea, and select elements - nothing more. I'm open to any suggestions and some of you smart guys could probably write this in half the lines I did.
Code:
//auto-save coding
var autosaveTimelapse=0;
var autosaveTimeout=3; //every n seconds
[code]...
<form name="new_page" action="test.php"><input type="checkbox" name="allowed[]" value="2">
<input type="checkbox" name="allowed[]" value="2">
<input type="checkbox" name="allowed[]" value="2">
<input class="button_140" type="button" value="Toevoegen"
if (!document.new_page.allowed[].checked){ popupalert('allowed'); }
else { this.form.submit(); }"></form>
This is a piece of the code I've written. It's supposed to check if one of the allowed[]-checkboxes is checked, and if not, to run function popupalert('allowed');. It's not working. Can someone tell me how to fix this?
Ok the setup is basically this. The user selects a option in a drop down field, whatever they select through javscript additional records are populated in a second select field. This second select field allows for multiple selections, however I am submitting the form to a php script and I want to capture the multiple selections in the second select field. To do that for php I need to turn the field into an array so I have to add the brackets, [], to the name of the select field.
In php you can name the field like so:
Code:
<select name="fld[]" size="1">
The problem is in the js function when I give it a field name with [] the script doesnt work. Here is the js function:
Code:
function channelform(select_value) {
IntPath = document.channel_form.cid[]
TheOptions = IntPath.options.length
[Code]..
You can see the [] for the cid field name. Whenever I add that to the field name the js script is broken. How do I get it to work so that I can pass an array to php when the form submits?
The form contains 3 file input tags. The name for each is an array. This is for further processing by PHP script. I want to make sure at least one of the file input tags has selected a file.
The rest of the validation script works, but I get a 'not object' error when I include the section that checks the file input tags. Code:
First I'm sure the answer to ths JS question is buried somewhere in the many item of this forum. Just could not find it. So I'm working on changes to a form developed by someone else. In the form the previous developer wrote the following:
<input type="checkbox" name="method[]" value="payroll_onetime">Payroll
<input type="checkbox" name="method[]" value="payroll_onetime">One-time
<input type="checkbox" name="method[]" value="paper">Paper Check
<input type="checkbox" name="method[]" "onlinebill">Online Bill
Note there are other form and HTML I removed.
So my problem is this. I'm trying to access the method checkbox array from a JS function. So I write:
function setPayrollStatus()
{
alert(document.profile.method.length);
}
This does give me that value of 4. Since there are 4 checkboxes for method I'm thinking this is correct. So next I add:
for (var idx=0; idx < document.profile.method.length; idx++)
{
alert(document.profile.method[idx].checked);
}
Now I get only 'undefined'.
What I want to accomplish is to check the first item. I thought I would be able to write something like: document.profile. method[0].checked = true;
If I change the form name tags from 'method[]' to 'method' it works. Problem is he also wrote the php back end processing for this form. And in PHP this syntax yeilds an array for the method vriable.
I am experience some problems reading a form variable from a
Javascript function. The point with this particular variable is that
its name has the following syntax:
<input name="tx_impexp[tt_content:159]"/>
I want to set this var to 1 from my javascript function, so I tried
to execute the following line of code:
document.frm_1.tx_impexp[exclude][tt_content:159].value=1;
Unfortunately the following error come up:
Error: missing ] in index expression
document.frm_1.tx_impexp[exclude][tt_content:159].value=1
--------------------------------------------------------------|
It seems Javascript expects to close down the bracket at the position
marked...An easy solution would be to change my var syntax but the
point is that I cannot since I am using an already made script and I
should not modify it.
Just wandering if this is due to a syntax error defined according to
Javascript specification language or there is something wrong with
this.
I really hope someone can assist: I am trying to take a form field:
[Code]...
Im trying to create an array using a form so that each time its stubmitted the value is stored in a session then the user can choose to save it or not, all without refreshing the page.Eg enter name and age, click add, it displays the name and age underneath the form, then enter a 2nd name and age click add, this is added to the array and displayed below the 1st entry.
View 2 Replies View RelatedIs there away to gather the values of all selected items in multiple select fields? Eg. I have three select lists.
Code:
<select name="tags1" id="tags1" value="tags1">
<option value="Male">Male</option>
<option value="Female">Female</option>
[code]....
I want to be able to get the results of what the user has selected in all three drop downs and place it into a single text field eg. if a user selects Male then Dog then Australia. The text field updates either on change or on submit to what the user has selected.
I am trying to accomplish a fairly basic task with javascript > my lack of Js knowledge has meant i have hit something of a roadblock.I need the a function to take an array from a form, remove the parsed variable from it and repost the form with the new array.This is what I have so far...
<script language="javascript">
function remove(SID) {
var speakers = document.form_name.elements["SID[]"];
[code]....
I have a number of checkboxes and radio buttons in an HTML form that are named as arrays, ie.
<INPUT type="checkbox" ID="i1" VALUE="MILK" NAME="Q1[]">
<INPUT type="checkbox" ID="i2" VALUE="SUGAR" NAME="Q1[]">
<INPUT type="checkbox" ID="i3" VALUE="BISCUIT" NAME="Q1[]">
I need to keep the 'NAME' as an array as above because of the form processing that is used after submit.
I was really hoping to use Javascript to validate the form and make sure that each checkbox group has at least one option selected , but my javascript messes up because the 'NAME' is Q1[] as opposed to Q1. I had been using:
<script>
function validate() {
if (!(mainform.Q1[0].checked || mainform.Q1[1].checked|| mainform.Q1[2].checked)) {
alert('Please answer question 1.');
event.returnValue=false;
}}
</script>
but this only works when I name the checkboxes NAME="Q1". Is anyone aware of how to get the validate function to work (or another way of validating the form) even when the checkboxes and radio buttons are named like NAME="Q1[]".
I want to validate a form. In the form is a text field named 'extra[]' where the user inputs a number. The number is what I want to validate.
However, the 'extra[]' field is dynamic and does not always appear in the form.
If it appears, there may be only 1 occurrence of it which means it's then not an array but there may also be multiple occurrences of it.
I have a script that validates (and work as it should) if the 'extra[]' field occurs multiple times and is thereby an array, but I can't figure out how to validate the 'extra[]' if there is only 1 and to not throw an error if it's not there at all. Code:
I am trying to open a window, with a url, and parameter from array form field. Here is the code:
<input type="text" name="parameter[1]" value="1223344"><input type="button" value="Check ID" + document.MainForm.parameter[1].value)">
I am getting that document.MainForm.parameter.1 is null or not an object.
How can I properly make javascript recorgenize the field?
I only manage to access non array named form fields.
Code:
<form method="post">
<input type=checkbox name=check[]>
[code]....
I have an order form where a customer can select a number of artwork prints supplied by different artists and suppliers. The name, price, postage amount and other details for each of the prints are held in a table in a MySQL database. As postage amount may vary between prints and suppliers of the prints we must have the customer select postage per print - not the amount just yes or no. The customer may select as many of these prints as he desires - printa, printb, printc, printd etc. through to printz. Many of the prints are provided by separate individual suppliers and must therefore have postage paid for each ordered print and this is automatically added by the order form. However some prints are provided by the same supplier and only one postage fee needs to be chosen (yes or no), so these are not automatically added and the customer must choose to pay postage on only one of the prints (not all 3 if he orders 3 of them).
So for postage purposes I have a postage code on the table in the MySQL database. For example printa, printb and printc are all supplied by the same supplier so each have a linked postage code of A. Similarly others may also be linked using different postage codes e.g. printx and printy may have a postage code of B. So whenever a customer chooses a print that does not have a linked postage code then the postage fee is automatically selected for him and charged to the total. However where prints are linked to the same postage code we must allow the costomer to select postage (yes or no), but we must force him to select yes or no for at least one of the linked prints.
So to do this I need a javascript validation alert to force the customer to choose yes for postage for at least one of the prints, not necessarily all of them, where they have a linked postage code. To do that I can add the the postage linked code as an array for each print selected to a form hidden field so that my javascript can use the field as follows: <input type="hidden" name="postagearray[]" value="<? echo $postagecode; ?>">
[Code]..
im pretty new to jQuery, but familiar with JS in general. im trying to get a dom element by id to change the read only attribute. using jQuery i'm doing the following: var field = $('#name[index][index]').
but when alerting the field value, i get [object Object] and not an inputObject as i would expect.
i can use the normal getElementById and it works as I would expect. Is this a problem with jQuery?