JavaScript - Access Elements With Same Ids Within Multiple Forms
Normally I would just use document.getElementById to get anything I need but here is my problem:
I have a zip code control that I load using AJAX. it has city, state, country, county and zip code. This gets loaded within a business application and at one point you can have both a bill to and ship to address forms on the screen at the same time, loading my zip control with the same fields, same ids and same name. This forced me to now pass in the form name that contains the control. I need to get to divs and spans within this form. Primarily as you type in a city or zip code, I am doing a hot search with a popup div that shows you results you can quickly choose from. The only time this becomes an issue is the situation I mentioned before when the zip code control is on the screen twice. I am not certain how to access the innerHTML of a span or div by way of the form name. Is this possible and if so what is the proper syntax? Here is a very basic example at its simplest form of my problem. Code: <form name="frm_billto" id="frm_billto"> <span id="myspan">Hello</span> </form> <form name="frm_shipto" id="frm_shipto"> <span id="myspan">World</span> </form> In the above example because the control was loaded twice, I now have 2 spans with the same ID. I want the innerHTML of the each span based on the form they are in. We wanted one control that we could use throughout the system that we could update in one place and the entire application be updated. Unfortunately we did not anticipate having it load more than once on the page. Thank you for any help Similar TutorialsHi All, I have html pages with code like <div> <script type="text/javascript" src="http://myserver2/mysite/addhtm.js"></script> </div> the script adds some html code and random images selected from second server inside an iframe tag in the div tag. I need to examine this added html and image properties in my page using javascript. A search on internet did not help, it says elements inside iframe coming from different domain can not be accessed. Is there any workaround or hack available to access iframe contents from page javascript? Thanks Hi All, I have a javascript application i have built http://dtp3.demodesign.co.uk/uploader/ Now this working in everything excluding IE but i don't under stand why it dose not work in IE it is a JSON Class that loads appends the content. and has an Iframe System to provide a powerful solution to work with AJAX to show file lists Any way if you go to that site it errors in Ie but work in every thing else any one got any idear why that is I'm reworking a 15 year old script. Here is the original general purpose routine that extracted a portion of one form to another form. Code: function FillForm(f) { for( i=FullName; i<=EndOfForm; i++) { self.document.forms[f].elements[i].value = FormData[i]; }; }; But NOW I'm supposed to use getElementById() Does that mean instead of the short routine I have to put one line for each Id tag and it is no longer general purpose and independent of the form being used? Is it OK to keep using the legacy script despite the Warning from the error console? IE is throwing an error stating window.document.forms[...].elements is null or not an object. in the following code Code: var changeHandler = function() { this.form.calculateDependencies(); return true; }; for(var i = 0; i < arguments.length; ++i) { for(var j = 0, e = window.document.forms[arguments[i]].elements; j < e.length; ++j) { addEvents([e[j]], ["change", "keyup", "focus", "click", "keydown"], changeHandler); e[j].hide = hideEl; e[j].show = showEl; } (e = window.document.forms[arguments[i]]).calculateDependencies = calcDeps; e.calculateDependencies(); } } FF and Chrome seem to work ok, but it breaks in IE. What am I doing wrong here? I am creating a recipe cookbook program. On the main page, I have a top frame (named "nav") and bottom frame (named "recipe_layout"). There is a listbox in the BOTTOM frame containing the recipe names, and a "View Recipe" button in the TOP frame. The user would select a recipe and then click the button to view the recipe in the bottom frame. I believe that I need to insert the code to make this work with the button (?), and I think my problem is that I'm not accessing the bottom frame correctly: CURRENT CODE FOR LISTBOX IN BOTTOM FRAME <form name="recipe_form" style="margin-top:30"> <select name="name_dropdown" multiple size="2"> <option selected="selected">Search byName</option> <option value="applepie.html">Apple Pie</option> CURRENT CODE FOR BUTTON IN TOP FRAME <input type="button" value="View Recipe" onclick="parent.recipe_layout.location.href='recipe_form.name_dropdown.options[selectedIndex].value'"> Thank you so much in advance!! Hi all - I'm having difficulty with the processing of 3 forms on my web page. We'll call my 3 forms A, B, and C. By default my page shows form A. The other 2 forms I have hidden via display:none My issue is when I have form B or C showing. Once I hit submit, say within form B for example, I'd like this form to remain for future entries/submital of data. However, instead what happens is form A appears. How do I get form B to remain, allowing for a user to submit multiple entries of data without going back to form A? Here's my code for form 'B' <div id="branches_info" style=" <?php echo $display_branches; ?> "> form method="post" action="annual_report_main.php" onsubmit="return validateBranches(this);"> <fieldset> <p><strong>Branch Location</strong></p><br /> <label for="branch_address" class="long">Street Address:</label> <input maxlength="50" type="text" name="branch_address" id="branch_address" value="<?php echo htmlentities($_POST['branch_address']);?>" /><br /> <div class="cleaner"></div> <label for="branch_city" class="long">City:</label> <input maxlength="20" type="text" name="branch_city" id="branch_city" value="<?php echo htmlentities($_POST['branch_city']);?>" /><br /> <div class="cleaner"></div> <label for="branch_state" class="long">State:</label> <input maxlength="2" type="text" name="branch_state" id="branch_state" value="<?php echo htmlentities($_POST['branch_state']);?>" /><br /> <div class="cleaner"></div> <label for="branch_zip" class="long">Zip Code:</label> <input maxlength="10" type="text" name="branch_zip" id="branch_zip" value="<?php echo htmlentities($_POST['branch_zip']);?>" /><br /> <div class="cleaner"></div> <div class="content_onecolumn"> <input type="submit" name="Branches" value="Submit to Database" class="inputSubmit" /> </div> <div class="content_onecolumn"> <input type="button" name="Finished" value="Finished" class="inputSubmit" onclick="window.open('https://www.dca.ca.gov/webapps/bppe/thankyou.php');return false" /> </div> </fieldset> </form> </div> Hello all, I am trying to update a site that has a cookie feature enabled so that a certificate can be retrieved later on. I am using a form to collect and put the cookie, but I have to use two buttons to get the information stored and then direct the user on through to the rest of the site. My question is: Can I combine these functions into the same button? I have scoured the web for solutions, but I can't seem to find anyone doing this exact thing. I know that websites do this type of thing all of the time. Here is the code that I am using. I am an html / css person. I am just getting into js. It is ugly, but I'm coping Code: <body> <div id="header"> </div> <div id="main"><br> <h2><SCRIPT LANGUAGE="JavaScript"> cookie_name = "dataCookie"; var YouEntered; function putCookie() { if(document.cookie != document.cookie) {index = document.cookie.indexOf(cookie_name);} else { index = -1;} if (index == -1) { YouEntered=document.cf.cfd.value; document.cookie=cookie_name+"="+YouEntered+"; expires=Saturday, 31-Dec-2011 23:59:59 GMT"; } } </SCRIPT> <FORM NAME="cf"> Enter Your Full Name as you would like it to appear on the completion certificate: <br> <INPUT TYPE="text" NAME="cfd" size="20"> <INPUT TYPE="button" Value="Enter" onClick="putCookie()"> </FORM> <h6>Select Continue to review the information</h6> <FORM METHOD="LINK" ACTION="cookie_2.htm"> <INPUT TYPE="submit" VALUE="Continue with Training"> </FORM></h2> </div> <div id="footer"> </div> </body> I have been looking around on the webs but have not found anything. I can find how to add multiple fields, but what if they reside on different forms on the same page? For example, here is my code with two forms: Code: <FORM name="form1"> <b>Size</b><input type="text" size="12" value="" name="size">* <b>Qty</b><input type="text" size="4" value="" name="qty" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"> <b>-</b> <input type=text size="10" value="" name="a1" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"><b>mm</b> <input type="text" size="15" value="" name="xtra">* <input type="hidden" size="4" value="304.8" name="b1"> <input type="hidden" value="0" name="ans1" size="10"> <input type="text" size="5" value="0" name="w1" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"><b>Lbs/Foot</b> <input type="text" size="7" value="0" name="tw1" readonly="readonly"><b>Total Lbs<b> </FORM> <FORM name="form2"> <b>Size</b><input type="text" size="12" value="" name="size">* <b>Qty</b><input type="text" size="4" value="" name="qty" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"> <b>-</b> <input type=text size="10" value="" name="a1" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"><b>mm</b> <input type="text" size="15" value="" name="xtra">* <input type="hidden" size="4" value="304.8" name="b1"> <input type="hidden" value="0" name="ans1" size="10"> <input type="text" size="5" value="0" name="w1" onkeyup="convert_to_feet(this.form);calculate_lbs(this.form)"><b>Lbs/Foot</b> <input type="text" size="7" value="0" name="tw1"><b>Total Lbs<b> </FORM> In this example, I want to sum the two fields named "tw1" (the last field on each form) into a text box. Is this possible? Hello, I'm in need of some help. I have a form that I want to clone and add up to 5 duplicates with slight changes. The changes a Add a second question and another set of related radio buttons for only the duplicates. Change the title in the Header to increment by 1 ex. Header 1, Header 2... I also would like to make the form elements "id" and "names" unique. Also, continue to use the add and remove button at the bottom. I hope this is doable. Any help will be appreciated. I have included my existing code. NOTE: for a visual, I mocked up the the original form and 1 copy of the fields in the html, not to be used. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script type="text/javascript" src="http://tablesorter.com/jquery-latest.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function() { $('#btnAdd').click(function() { var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have var newNum = new Number(num + 1); // the numeric ID of the new input field being added var newElem = $('#section' + num).clone().attr('id', 'section' + newNum); newElem.children(':first').attr('id', 'first' + newNum).attr('name', 'first' + newNum).val(''); newElem.children(':first').attr('id', 'last' + newNum).attr('name', 'last' + newNum).val(''); newElem.children(':first').attr('id', 'phone' + newNum).attr('name', 'phone' + newNum).val(''); newElem.children(':first').attr('id', 'email' + newNum).attr('name', 'email' + newNum).val(''); newElem.children(':first').attr('id', 'yes' + newNum).attr('name', 'yes' + newNum).val(''); newElem.children(':first').attr('id', 'no' + newNum).attr('name', 'no' + newNum).val(''); $('#section' + num).after(newElem); $('#btnDel').attr('disabled',''); if (newNum == 5) $('#btnAdd').attr('disabled','disabled'); }); $('#btnDel').click(function() { var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have $('#section' + num).remove(); // remove the last element $('#btnAdd').attr('disabled',''); // enable the "add" button // if only one element remains, disable the "remove" button if (num-1 == 1) $('#btnDel').attr('disabled','disabled'); }); $('#btnDel').attr('disabled','disabled'); }); </script> <form id="myForm"> <div id="section1" style="margin-bottom:4px; border-bottom:1px solid #000; width: 400px;" class="clonedInput"> <br> <br> <div style=" font-weight:bold; border: 1px solid #000; padding:4px;background:#CCC; font-size:18px; margin-bottom:5px;">Header</div> First: <input type="text" name="first1" id="first1" /> <br> <br> Last: <input type="text" name="last1" id="last1" /> <br> <br> <br /> <div style=" font-weight:bold;padding:4px;">Header 2</div> <div>Show this question and radios on load of page.</div> <div> <input type="radio" id="yes1" class="eRad" name="yes1" value="" /> <label class="" for="yes">Yes</label> <input type="radio" id="no1" class="eRad" name="no1" value="" /> <label class="" for="no">No</label> </div> Phone: <input type="text" name="phone1" id="phone1" /> <br> <br> Email: <input type="text" name="email1" id="email1" /> </div> <div id="section1" style="margin-bottom:4px; border-bottom:1px solid #000; width: 400px;" class="clonedInput"> <br> <br> <div style=" font-weight:bold; border: 1px solid #000; padding:4px;background:#CCC; font-size:18px; margin-bottom:5px;">Header 2 (increment this number)</div> <div>Show this new question and radios on all copies</div> <div> <input type="radio" id="yes_a2" class="eRad" name="yes_a2" value="" /> <label class="" for="yes">Yes</label> <input type="radio" id="no_a2" class="eRad" name="no_a2" value="" /> <label class="" for="no">No</label> </div> First: <input type="text" name="first2" id="first2" /> <br> <br> Last: <input type="text" name="last2" id="last2" /> <br> <br> <br /> <div style=" font-weight:bold;padding:4px;">Sub Header 2 (increment this number)</div> <div>Show this question and radios on load of page.</div> <div> <input type="radio" id="yes_a2" class="eRad" name="yes_a2" value="" /> <label class="" for="yes">Yes</label> <input type="radio" id="no_a2" class="eRad" name="no_a2" value="" /> <label class="" for="no">No</label> </div> Phone: <input type="text" name="phone2" id="phone2" /> <br> <br> Email: <input type="text" name="email2" id="email2" /> </div> <div style="margin-top:10px;"> <input type="button" id="btnAdd" value="add another name" /> <input type="button" id="btnDel" value="remove name" /> </div> </form> </body> </html> -Cheers I'm having a problem with the <CANVAS> element in JavaScript. here's what i'm trying to do: I need 3 different canvas elements for writing a signature to. they must all 3 be visible at the same time My problem that i'm having is that i can't seem to get the code to work which will write to more than one canvas. here's my code: Code: <html> <head> <script language="javascript"> function WriteSignature(element, event) { document.addEventListener("mousemove", PenHandler, true); document.addEventListener("mouseup", upHandler, true); event.stopPropagation(); event.preventDefault(); function PenHandler(event) { var x = event.clientX; var y = event.clientY; // mouse event goes here var canvas1 = document.getElementById("Canvas1"); var ctx = canvas1.getContext("2d"); var PenSize = 2; ctx.fillStyle = "Black"; ctx.fillRect (x, y, PenSize, PenSize); event.stopPropagation(); } function upHandler(event) { document.removeEventListener("mouseup", upHandler, true); document.removeEventListener("mousemove", PenHandler, true); event.stopPropagation(); } } </script> </head> <body> <Canvas id="Canvas1" Width="400" Height="100" Style="border:2px solid black" onmousedown="WriteSignature(this, event);"></Canvas><br><br> <Canvas id="Canvas2" Width="400" Height="100" Style="border:2px solid black" onmousedown="WriteSignature(this, event);"></Canvas><br> </body> </html> Hello, I'm trying to make a simple webpage with two input text boxes that when submitted when empty, I'll get an error pop-up telling me which ones are empty, both, first name, or last name. When there's only one if, the script works. But when there's multiple else ifs, nothing happens if I press submit. Can someone help me? Code: <html> <head> <script type="text/javascript"> function validateForm() { var x=document.forms["myForm"]["firstname"].value; var y=document.forms["myForm"]["lastname"].value; if (x==null || x=="" && y==null || y=="") { alert("Please put in your first and last name."); return false; } else if (x==null || x=="") { alert("Please put in your first name."); return false; } else if (y==null || y=="") { alert("Please put in your last name."); return false: } } </script> </head> <body> <form name="myForm"> First name: <input type="text" name="firstname"><br> Last name: <input type="text" name="lastname"> <input type="submit" value="Submit" onclick="validateForm()"> </form> </body> </html> I'm creating a paypal webpage and am having some issues with input values updating based on which item the user has selected. The boxes I need to update are the amount, item number and item name. I have the following code but it only updates the first form. If I make a change to the second set of options it updates the first form instead of the second. Any help would be much appreciated. Code: function details(val) { var info = val.split("|"); document.getElementById('num').value = info[0]; document.getElementById('price').value = info[1]; document.getElementById('package_name').value = info[2]; } <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <select name="dy" Onchange="details(this.value);"> <option value="1|3|Package 1">Package 1</option> <option value="2|6|Package 2">Package 2</option> <option value="3|9|Package 3">Package 3</option> </select> <input type="text" id="num" name="item_number" value="1"> <input type="text" id="price" name="amount" value="3"> <input type="text" id="package_name" name="item_name" value="Package 1"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><input type="hidden" name="add" value="1"> </form> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <select name="pt" Onchange="details(this.value);"> <option value="4|6|Package 4">Package 4</option> <option value="5|9|Package 5">Package 5</option> <option value="6|12|Package 6">Package 6</option> </select> <input type="text" id="num" name="item_number" value="4"> <input type="text" id="price" name="amount" value="6"> <input type="text" id="package_name" name="item_name" value="Package 4"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><input type="hidden" name="add" value="1"> </form> fyi, I have limited experience with web programming (even less with javascript). I am trying to search a database of molecules and display several columns for each returned molecule in a table in a new page (view_all.cgi). Within this table I have a button for each molecule from the database which I would like to be able to click it and view all of it's information in a new page (view_one.cgi) However, I also have a column in my table in view_all.cgi filled with check boxes so that only some of the returned molecules can be checked and then downloaded using a script (get_checked.cgi). QUESTION: How can I handle the table data so that one button sends one row of the table to view_one.cgi, while another button sends multiple columns of the table to get_checked.cgi without using nested forms? Thanks, Tom EDIT: A better question. I have the first part of my question working (sending one row of a table to view_one.cgi). So, using javascript, how can I get the status (checked/unchecked) of all the check boxes on a page and send the information to get_checked.cgi? hi, I am now building my website as a final project for my year. I am doing graphic design, so the website is actually some kind of portfolio. The idea of this website (which is not yet online) is this : it is some kind of big pasteboard on which i will display all the work i have done in my academy since a couple of years. The pasteboard is at the moment a background image/color field of given dimension (i figure that was the only way to do what i wanted...see further) Every works/image load on a random place and then can be dragged, and dropped (this part i already figured out). At the moment, every image (for every project), is inside a <div>. What i need help for is this: at the moment, my function successfully load 1 element at random position. I now want this function to work separately, for every <div>, so that every image is randomly placed on load, on the background image (and not the browser window, which is smaller). Here is the code i have for the moment (sorry for the mess, i really am just beginning! and truely, i don't get half of this, i just know it is working at the moment): Code: <head> <!--// function random start position--> <script> var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById; if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1; else { var nsDOM = ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1;}} function xDOM(objectId, wS) { if (stdDOM) return wS ? document.getElementById(objectId).style: document.getElementById(objectId); if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId]; if (nsDOM) return document.layers[objectId]; } // More Object Functions function setObjVis(objectID,vis) {var objs = xDOM(objectID,1); objs.visibility = vis;} function moveObjTo(objectID,x,y) {var objs = xDOM(objectID,1); objs.left = x; objs.top = y;} // Browser Window Size and Position function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;} function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;} function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;} // Random Position Script var xxx = Math.floor(Math.random()* (pageWidth()-230)); var yyy = Math.floor(Math.random()* (pageHeight()-50)); function start() {var x = (posLeft()+xxx) + 'px'; var y = (posTop()+yyy) + 'px'; moveObjTo('myobj',x,y); setObjVis('myobj','visible');} window.onload = start; window.onscroll = start;// JavaScript Document </script> </head> <body bgcolor="#9A9B95" background="../website/background.jpg"> <div id="myobj" style="position:absolute" > <img src="oblique strategies holes.jpg" width="595" height="842" style="position:absolute" class="dragme"/> </div> <div id="div2"> <img src="oblique strategies choices.jpg" width="842" height="595" style="position:absolute" class="dragme" /> </div> </body> now, what i really want is this function to work for every <div> but i know there are also some flaws (that i'm unfortunately unable to fix myself): the integers "230 and 50" in the "random position script" should be replaced byt the width and heigh of the image/div (so i guess i should find a function that can get those numbers, name them "ImgWeidth" and "ImgHeigh" so that those integer can be called in this "random position" function. also, once the div 'myobj' is loaded, randomly, it behaves like if position=fixed (so stays on the spot when i scroll down the window). I think this is because it calculates the position according to the browser window and not my background. this has be fixed, because i don't want all my images to load only in the browser window (but on the whole pasteboard/background image). well, i guess this is already 3 questions in one. so i will let it like that for the moment. Sorry if i'm saying too much/not enough... beginners mistake!:confused: thanks in advance for any help you will give me! I posted a thread a few days ago concerning a bit of javascript code to make checking one checkbox clear another one. I got some great, prompt help. However, I just got back to working on that web page, and realized that the functions only work on the first form on my web page. I have many forms and they are actively named using php. Here's are the functions (these works for just the first form on the page): Code: <script type="text/javascript"> function undo_Changes() { if (document.getElementById("Complete").checked==true) { document.getElementById("Needs_Change").checked=false; } } function undo_Complete() { if (document.getElementById("Needs_Change").checked==true) { document.getElementById("Complete").checked=false; } } </script> I call them from the checkboxes involved: Code: <input name="Complete" id="Complete" value="Yes" <?php echo($Complete=="Yes") ? "checked" : ""; ?> size="4" type="checkbox" onChange="this.style.color='#FF0000'" onClick="undo_Changes()"> <input name="Needs_Change" id="Needs_Change" value="Yes" <?php echo($Needs_Change=="Yes") ? "checked" : ""; ?> size="4" type="checkbox" onClick="undo_Complete()"> Here's how my forms are named: Code: <?php $DocName = "Schedule".$count; ?> <form name="<?php echo $DocName; ?>" action="ScheduleCode.php" method="post" id="<?php echo $DocName; ?>"> I've tried the following and it doesn't work at all: Code: <script type="text/javascript"> function undo_Changes(myForm) { if (myForm.getElementById("Complete").checked==true) { myForm.getElementById("Needs_Change").checked=false; } } function undo_Complete(myForm) { if (myForm.getElementById("Needs_Change").checked==true) { myForm.getElementById("Complete").checked=false; } } </script> <input name="Complete" id="Complete" value="Yes" <?php echo($Complete=="Yes") ? "checked" : ""; ?> size="4" type="checkbox" onChange="this.style.color='#FF0000'" onClick="undo_Changes(this.form)"> <input name="Needs_Change" id="Needs_Change" value="Yes" <?php echo($Needs_Change=="Yes") ? "checked" : ""; ?> size="4" type="checkbox" onClick="undo_Complete(this.form)"> Thanks for any help. Lisa Hi all, I have multiple forms on one page with the same element name and one of them is the <span>. Below is my sample code for a simple html file for testing purposes. I have no problem accessing the <input> element, but i had problems with the <span> element. Anyone knows why? In this scenario, i won't be able to use the document.getElementById() as both <span> have the same name. Code: <html> <head> Test <SCRIPT LANGUAGE="JavaScript"> // JavaScript statements go here function test(tmpForm) { window.alert(tmpFrm.elements["weight"].value); window.alert(tmpForm.elements["error"].innerHTML); } </SCRIPT> </head> <body> <form id="form_137" name="form_137"> <input id="weight" name="weight" value="" /> <span id="error" name="error">abc</span> <INPUT TYPE="button" id="btnSubmit" NAME="btnSubmit" VALUE="Submit" onClick="test(this.form);"> </form> <form id="form_137_down" name="form_137_down"> <input id="weight" name="weight" value="" /> <span id="error" name="error">zzz</span> <INPUT TYPE="button" id="btnSubmit" NAME="btnSubmit" VALUE="Submit" onClick="test(this.form);"> </form> </body> </html> I have a document that contains four forms. I want to run a function only in the form the user is currently in. I keep getting the "document.my_form_name is undefined" error. I've tried all sorts of ways of doing this but can't find a solution. Here's a snippet of the HTML: Code: <form id="my_form_1" name="my_form_1" action="some action" method="POST"> // in here I call the function onchange_display_sel_droplist and // pass through the name of the form </form> <form id="my_form_2" name="my_form_2" action="some action" method="POST"> bla bla </form> Here's the part of the function in question: Code: function onchange_display_sel_droplist(my_value, my_object, my_text_obj, my_form_name) { // create array with all the divs found var arr = new Array(); arr = document.my_form_name.getElementsByTagName( "div" ); // loop through array for(var i=0; i < arr.length; i++) { var tagId = document.my_form_name.getElementsByTagName( "div" ).item(i).id; // find all the divs with ID "my_selected_div__" if ( tagId.indexOf("add_selected_div__") > -1 ) { // hide all document.my_form_name.getElementById(tagId).style.display = "none"; } } // display selected object (droplist) document.my_form_name.getElementById(my_object).style.display = ""; } I made a php page with multiple forms with javascript code in it. The javascript makes an input field for the date. The problem is that the script interfers between other scripts in the other forms and i get wrong orderdate. Code: <form action='dataadd.php' name='$id'>"; $datestime=time(); echo "<input type=hidden name=dateid value='$id'>"; echo "<input type=hidden name=datestime value='$datestime'>";?> <script type="text/javascript"> DateInput('orderdate', true, 'yyyy-mm-dd')</script>.... hello everybody! this is my first atempt in writing javascript and i have a problem which I have no idea how to solve. I want to take the values from several dropdown forms and make some calculations whit those in order to display a number. Unfortunately the script responts in a way that i cannot identify what is happening. this is a shorten example of my script. Code: <html> <head> <script type="text/javascript"> function calcul() { var pcno = document.plithospc.listplpc.value; var ndno = document.plithosnd.listplnd.value; var hotline = document.hotlform.listhotl.value; var sumhotline = 0; if (hotline == 2) { sumhotline = 8*(1+0.5*pcno) + 2*(1+0.5*ndno); } else if (hotline == 3) { sumhotline = 16*(1+0.5*pcno) + 4*(1+0.5*pcno); } else { sumhotline = 0; } document.write(sumhotline); </script> </head> <body> <FORM NAME="plithospc"> <SELECT NAME="listplpc"> <OPTION SELECTED="SELECTED" VALUE=0>choose one</OPTION> <OPTION VALUE=1>-1-</OPTION> <OPTION VALUE=2>-2-</OPTION> <OPTION VALUE=3>-3-</OPTION> </SELECT> <FORM NAME="plithosnd"> <SELECT NAME="listplnd"> <OPTION SELECTED="SELECTED" VALUE=0>choose one</OPTION> <OPTION VALUE=1>-1-</OPTION> <OPTION VALUE=2>-2-</OPTION> <OPTION VALUE=3>-3-</OPTION> </SELECT> <FORM NAME="hotlform"> <SELECT NAME="listhotl"> <OPTION SELECTED="SELECTED" VALUE=0>choose one</OPTION> <OPTION VALUE=1>1st selection</OPTION> <OPTION VALUE=2>second selection</OPTION> <OPTION VALUE=3>third selection</OPTION> </SELECT> <button type="button" onclick="calcul()">click me</button> </body> does anyone knows how to fix this? thanks in advance I'm using the autofill forms plugin for firefox which can be found he https://addons.mozilla.org/en-US/firefox/addon/4775 I use it to automatically fill various web forms, duh. But I would like certain values to be chosend randomly from a list I create. I contacted the developer and he said the add on probably does not need a new feature because there is a 'dynamic tags' function to fill certain forms with dynamic values (e.g. the current time or date). He has given over the project to another developer and told me I probably would find a solution in a good javascript programming forum. So here I am! Can anyone help me with this? Basically, I just need a javascript code which chooses on item from an array randomly, I guess? I'm not a programmer myself, so any help would be greatly (!) appreciated. Thanks a lot in advance for any further guidance! Note: Here are sample dynamic tags from the plugin: <datetime> new Date().toLocaleString() <useragent> navigator.userAgent <langcode> navigator.language <resolution> screen.width+'x'+screen.height <clipboard> this.getClipboardText() |