JavaScript - Auto Populate Html Form W/ Javascript
Hello All,
I have a form where the number of input fields (lets call them B through N) is determined by the length of a php array. Above those input fields is another field (lets call this field input A) that I would like to be auto populated based on what the user enters in fields B through N. Here is my code. The first table (with all of the "totals" fields) holds all of the input fields that I would like to auto update. These fields should auto update so that every input in EACH of the "fy" fields in the second table is added together. Example: every input in the id="fy_{$fy.fy}_high_impact_cost" field should be added together as the user enters them, and the id="totals_high_impact_cost" field should be auto updated with that total. Code: <form method="post" name="submit" action="new_item.php" accept-charset='UTF-8'> <table border="box" width="100%"> <tr> <td align="center">$<input id="totals_high_impact_cost" size="3" name="totals_high_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_most_likely_impact_cost" size="3" name="totals_most_likely_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_low_impact_cost" size="3" name="totals_low_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_actual_expense" size="3" name="totals_actual_expense" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_high_mitigation_cost" size="3" name="totals_high_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_most_likely_mitigation_cost" size="3" name="totals_most_likely_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_low_mitigation_cost" size="3" name="totals_low_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_cost_in_scope" size="3" name="totals_cost_in_scope" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_unfunded_threat" size="3" name="totals_unfunded_threat" maxlength="20" style="text-align: right" />M</td> </tr> </table> {foreach value=fy from=$php_array} <table> <tr> <td align="center">$<input id="fy_{$fy.fy}_high_impact_cost" size="3" name="fy_{$fy.fy}_high_impact_cost" maxlength="20" style="text-align: right" value="{$fy.high_impact_cost}" onchange="update_totals_high_impact_cost()" />M</td> <td align="center">$<input id="fy_{$fy.fy}_most_likely_impact_cost" size="3" name="fy_{$fy.fy}_most_likely_impact_cost" maxlength="20" style="text-align: right" value="{$fy.most_likely_impact_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_low_impact_cost" size="3" name="fy_{$fy.fy}_low_impact_cost" maxlength="20" style="text-align: right" value="{$fy.low_impact_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_actual_expense" size="3" name="fy_{$fy.fy}_actual_expense" maxlength="20" style="text-align: right" value="{$fy.actual_expense}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_high_mitigation_cost" size="3" name="fy_{$fy.fy}_high_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.high_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_most_likely_mitigation_cost" size="3" name="fy_{$fy.fy}_most_likely_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.most_likely_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_low_mitigation_cost" size="3" name="fy_{$fy.fy}_low_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.low_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_cost_in_scope" size="3" name="fy_{$fy.fy}_cost_in_scope" maxlength="20" style="text-align: right" value="{$fy.cost_in_scope}" />M</td> </tr> </table> {/foreach} </form> Please email me at alexhall12315@yahoo.com if you would like more explanation. Thanks in advance for any help!!! =) Similar TutorialsI have two slightly different forms on the same page, but I want the values in form1 to auto populate the same form fields in form2. 1 field is a text field, the rest are drop down menus. How would I accomplish this? Link to tutorial would be much appreciated. Thanks
Hi All! Thanks in advance to any and all who help me. What we are trying to do is have a form where customers can use a conditional logic based form that upon submission will redirect to checkout with an appropriate product bundle being populated in the shopping cart. I have some experience with creating forms, in fact I have made a decent form that I have modified from an online form builder... the problem is I have no idea how to auto-fill the shopping cart... period. From what I have read in my research this should be a function of Javascript. I have a decent working knowledge of php, and html, but I am pretty clueless when it comes to Javascript, if anyone could point me in the right direction for this project I would really appreciate it. Hi, I'm working on a menu update form. I'm pulling the existing data from mysql and posting it into a form, using php. This works fine. But now I want the user to be able to modify the data and perform and update query to the database with the changes. I cannot figure out how to get the modified php text box data into my html form text boxes so I can run an update query. I would be ok with a button that transfers the php text box data to the html form data. Hope this is clear what I'm trying to do, seems simple enough, but I can't figure it out. Thanks in advance for any ideas. This form collects info of the customer who wishes to select add-ons that would be applied to their digital photos. Examples of add-ons: Photo makeover Add object or person Crop image Have a look at the form Once a customer selects one of the options (Photo Manipulation or Photo Restoration for example - radio buttons) and then one or more Add-ons (check boxes in the Html form), enter their details and upload a photo, they hit the submit button and it then takes them to the PayPal checkout page where the total amount is shown. (see image below) The Issue: In the PayPal page, it now shows the total amount whichever add-ons you select, however it keeps showing "Add object or person" as well as all the 5 main options (radio buttons on the form) no matter what I select. This will be an issue as I will not know exactly which add-ons the customer has selected. Can someone please help me complete the coding so that the add-ons show on the PayPal checkout page. I look forward to your reply/replies. Kind Regards Rafi p.s: Could this be a possible solution? Even if it is, can someone help by completing the code? In order to send the options/add-ons the customer selects I may need to use the onX and osX variables (Where X is a number starting with 0 and incrementing by 1 see below), These can be used to set options for the add-onsthey select. The onO is the "option name" and os0 is the "option choice". So for example: <input type="hidden" name="on0" value="Photo manipulation"> <input type="hidden" name="os0" value="Whatever add-ons the customer selects"> <input type="hidden" name="on1" value="Photo restoration"> <input type="hidden" name="os1" value="Whatever add-ons the customer selects"> Hi, How can I auto populate the data by dropdown selected? and my dropdown result already appear as well, the code as following: PHP Code: <?php echo '<tr> <td>'.$customer_data.'</td> <td><select name="customer_id">'; foreach ($customers as $customer) { if ($customer['customer_id'] == $customer_id) { echo '<option value="'.$customer['customer_id'].'" selected="selected">'.$customer['name'].'</option>'; } else { echo '<option value="'.$customer['customer_id'].'">'.$customer['name'].'</option>'; } } echo '</select> </td> </tr>'; ?> and the result of dropdown above listed as admin customer1 FREE loaded from following db PHP Code: INSERT INTO `my_customer` (`customer_id`, `name`, `firstname`, `lastname`) VALUES (8, 'admin', '', ''), (6, 'customer1', 'ok', ''), (7, 'FREE', 'marj', 'om'); so whenever dropdown selected i want the all data below: PHP Code: <tr> <td><?php echo $firstname; ?></td> <td><?php echo $lastname; ?></td> </tr> also auto populate, it seem need javascript/ajax/jquery to fixed it, I was Wondering if someone could help me, and thanks in advance I 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. php array creation: Code: if ($row_locations) { while ($row_locations = mysql_fetch_assoc($locations)) { $mail[$row_locations['comp_id']]=array('mailto'=>$row_locations['mailto'], 'madd'=>$row_locations['madd'], 'madd2'=>$row_locations['madd2'], 'mcity'=>$row_locations['mcity'], 'mstate'=>$row_locations['mstate'], 'mzip'=>$row_locations['mzip'], 'billto'=>$row_locations['billto'], 'badd'=>$row_locations['badd'], 'badd2'=>$row_locations['badd2'], 'bcity'=>$row_locations['bcity'], 'bstate'=>$row_locations['bstate'], 'bzip'=>$row_locations['bzip']); } } javascript function - this should create the array and send variables to text fields. Code: function updateAddress() { var mail = $.parseJSON(<?php print json_encode(json_encode($mail)); ?>); { if (comp_id in mail) { document.getElementById('mailto').value=mail.comp_id.mailto.value; document.getElementById('madd').value=mail.comp_id.madd.value; document.getElementById('madd2').value=mail.comp_id.madd2.value; document.getElementById('mcity').value=mail.comp_id.mcity.value; document.getElementById('mstate').value=mail.comp_id.mstate.value; document.getElementById('mzip').value=mail.comp_id.mzip.value; } else { document.getElementById('mailto').value=''; document.getElementById('madd').value=''; document.getElementById('madd2').value=''; document.getElementById('mcity').value=''; document.getElementById('mstate').value=''; document.getElementById('mzip').value=''; } } } Where is this breaking? Thanks in advance. Hi, I'm pretty new in Javascript. I searched alot but didn't find any answer to my problem I have. What I want to do: - I have a cell A1 - I want the script to make a new cell B1 - After that I want the script to make a new cell C1 - After that I want the script to make a new cell D1 - After that I wa .... etc .... till I got 20 cells in total. This has to go automatic so not by use of a client sided button. I also need every cell to get his own IDnumber like A1 ID=1, B1 ID=2, C1 ID=3, etc to communicate with database and mysql. But maybe I have to use php for that. Thanx for any help! Best regards, Thoaren My html form code is <html> <head> <script type="text/javascript" src="2.js"></script> </head> <body> <h1 id="remain"></h1> <form action="3.php" method="post" id="form1" name="form1"> <input type="text" name="id"> <input type="submit" name="submit" value="submit"> </form> </body> </html> I need to submit the form after coundown.Here is my countdown script file window.onload=counter; function counter() { var seconds = 5; countDown(); function countDown() { document.getElementById("remain").innerHTML=seconds; if(seconds>0) { seconds=seconds - 1; setTimeout(countDown,1000); } if(seconds == 0) { document.form1.submit(); } } } Countdown is working but form does not submit after countdown.Please help me regarding this.Thanks in advance hello i am trying to fire a form which after the call to retrieve the data, populate the form with the data. i can see from firebug that the json data is being captured, but cannot seem to be able to populate the form with it. i am using a jquery plugin facybox, that opens the form, but the fields are blank. i have attached my code and would be grateful if someone could tell me where i am going wrong? many thanks js code Code: <script type="text/javascript"> function edit(com, grid) { if (com == 'Edit') { if($('.trSelected').length>0){ if($('.trSelected').length>1){ alert('Please select just one row'); return; } var items = $('.trSelected'); var itemlist =''; for(i=0;i<items.length;i++){ itemlist+= items[i].id.substr(3); } $.ajax({ type: "POST", dataType: "json", url: "tempcontact.php", data: "items="+itemlist, success: function(data){ document.getElementById('id').value = data.id; document.getElementById('email').value = data.email; $("#flex1").flexReload(); } }); /*and so on then you can call facybox*/ jQuery.facybox({ div: "#editform"}); } else{ alert('Please select a row to edit.'); } } } </script> form Code: <div id="editform" style="display:none;"> <form action="conedit.php" method="post" class="webform"> <fieldset> <legend><span>Update Contact</span></legend> <br /> <div id="dataText">Please delete the fields if there is no data 'No data to display'.</div> <label for="id">ID:</label> <input id="id" name="id" class="text" type="text" value="" /> <label for="name">Full Name:</label> <input id="name" name="name" class="text" type="text" value="" /> <label for="email">Email address:</label> <input id="email" name="email" class="text" type="text" value="" /> <label for="phone">Telephone:</label> <input id="phone" name="phone" class="text" type="text" value="" /> <label for="mobile">Mobile:</label> <input id="mobile" name="mobile" class="text" type="text" value="" /> <label for="fax">Fax:</label> <input id="fax" name="fax" class="text" type="text" value="" /> <label for="notes">Notes:</label> <textarea name="notes" cols="25" rows="3"></textarea> </fieldset> <input class="submit" type="submit" name="submit" value="Update" /> </form> </div> Hi, I'm new to Javascript and need to help with something, I'll try and explain this as best as I can but feel free to ask questions if it doesn't make sense. I'm basically building a javascript/html calculator but I need the calculation to appear gradually in a table, the table need to be 3 columns accross and add a row each time a calculation button is pressed, the first column can remain blank for now but will need to contain a text field eventually, second column needs to show the calculation symbol, third column shows the number. Here's an example: 4+2+7-5=8 |Blank| | 4 | |Blank| + | 2 | |Blank| + | 7 | |Blank| - | 5 | |Blank| = | 8 | Here's the code I have so far so you can get a feeling of what it looks like, this table need to go into the area div and will replace what is currently the Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sample Widget</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="basic.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="basic.js"></script> <meta name="generator" content="Nokia WRT extension for Visual Studio 2.0" /> <script type="text/javascript" language="javascript"> function UpdateInput(a, b) { var MyElement = document.getElementById("Input"); MyElement.innerHTML = MyElement.innerHTML + a; var MyElement = document.getElementById("Area"); MyElement.innerHTML = MyElement.innerHTML + b; } function Calculate() { var result = eval(document.getElementById("Input").innerHTML); var total = document.getElementById("Total"); total.innerHTML = result; var MyElement = document.getElementById("Area"); MyElement.innerHTML = MyElement.innerHTML + '<br>=' + result; } </script> </head> <body onLoad="init()"> <div id="Main"> <table cellpadding="0" cellspacing="0" width="100%"> <div id="Area"> </div> </table> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td class="style1">Total:</td> <td> <div id="Total"></div> </td> </tr> <tr> <td colspan="2"> <div id="Input"></div> </td> </tr> </table> <table cellpadding="0" cellspacing="0"> <tr> <td><img src="Images/plus.png" onclick="UpdateInput('+','<br>+')" /></td> <td><img src="Images/minus.png" onclick="UpdateInput('-','<br>-')" /></td> <td><img src="Images/times.png" onclick="UpdateInput('*','<br>*')" /></td> <td><img src="Images/divide.png" onclick="UpdateInput('/','<br>/')" /></td> </tr> <tr> <td><img src="Images/7.png" onclick="UpdateInput(7,7)" /></td> <td><img src="Images/8.png" onclick="UpdateInput(8,8)" /></td> <td><img src="Images/9.png" onclick="UpdateInput(9,9)" /></td> <td><img src="Images/percent.png" onclick="UpdateInput('%','<br>%')" /></td> </tr> <tr> <td><img src="Images/4.png" onclick="UpdateInput(4,4)" /></td> <td><img src="Images/5.png" onclick="UpdateInput(5,5)" /></td> <td><img src="Images/6.png" onclick="UpdateInput(6,6)" /></td> <td><img src="Images/oneoverx.png" /></td> </tr> <tr> <td><img src="Images/1.png" onclick="UpdateInput(1,1)" /></td> <td><img src="Images/2.png" onclick="UpdateInput(2,2)" /></td> <td><img src="Images/3.png" onclick="UpdateInput(3,3)" /></td> <td><img src="Images/plusminus.png" /></td> </tr> <tr> <td><img src="Images/0.png" onclick="UpdateInput(0,0)" /></td> <td><img src="Images/dot.png" onclick="UpdateInput('.','.')" /></td> <td><img src="Images/equals.png" onclick="Calculate()" /></td> <td><img src="Images/sub.png" /></td> </tr> </table> </div> </body> </html> Hi Guys, I am after populating a HTML box (or another language if html wont do) with a number of different files pdfs, exe's etc for customer to download. The content of this box will depend on the choices from two drop down lists. I have got two drop down lists setup filtering off each other... I have thought about tagging each document and then pulling up a file off the choices selected? Not sure the best way to go about this. Regards Heres the code so far.... Code: <HTML> <HEAD><TITLE>prototype CP</Title> <style type="text/css"> .style1 { text-align: center; } .style2 { font-size: small; color: #FFFFFF; } .style3 { font-size: small; } </style> </Head> <BODY OnLoad="BuildContacts(0);" style="background-color: #336699; background-image: url('back.jpeg')"> <FORM Name="myForm"> <div class="style1"> <span class="style2">I have a </span> <font color="#000000"> <SELECT Name="SalesNames" OnChange="BuildContacts(this.selectedIndex);" class="style3"> <OPTION Value=""> <OPTION Value="nexgen">nexgen <OPTION Value="zimbra">zimbraCS <OPTION Value="exchange">exchange </Select></font><span class="style2"> mailbox and I want to set it up on: </span> <font color="#000000"> <SELECT Name="SalesContacts" class="style3"> <OPTION Value="">-------- </Select> </font> </div> </Form> </Body> </Html> <SCRIPT Language="JavaScript"><!-- //Build arrays for each mailbox type Contacts=new Array(4); Contacts[0]=new Array(3); Contacts[1]=new Array(2); Contacts[2]=new Array(5); Contacts[3]=new Array(4); //Nexgen Contacts[0][0]=""; Contacts[0][1]="Outlook"; Contacts[0][2]="mac mail"; Contacts[0][3]="entourage"; Contacts[0][4]="iPhone"; Contacts[0][5]="Blackberry"; Contacts[0][6]="other mobile phone"; //Zimbra Contacts[1][0]="Outlook"; Contacts[1][1]="mac mail"; Contacts[1][2]="entourage"; Contacts[1][3]="iPhone"; Contacts[1][4]="Blackberry"; Contacts[1][5]="other mobile phone"; //Exchange Contacts[2][0]="Outlook"; Contacts[2][1]="mac mail"; Contacts[2][2]="entourage"; Contacts[2][3]="iPhone"; Contacts[2][4]="Blackberry"; Contacts[2][5]="other mobile phone"; //Call this to build the Contact list for the specified Salesperson function BuildContacts(num) { //Select the first Contact document.myForm.SalesContacts.selectedIndex=0; //For every contact in the array for this person, add a new option for(ctr=0;ctr<Contacts[num].length;ctr++) { document.myForm.SalesContacts.options[ctr]=new Option(Contacts[num][ctr],Contacts[num][ctr]); } //Set the length of the select list document.myForm.SalesContacts.length=Contacts[num].length; } //--></Script> Hello, I don't know if this can be done in Javascript, or requires any other language but i was wondering if this would be possible. I would like to embed this Javascript code in to a PHP file and then for it to run automatically upon the PHP file loading: Code: <td class="smallDesc"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </td> The Javascirpt is the Facebook Share button that basically allows users that have Facebook to share the page there currently on in their Facebook status by pressing the button, but if there not logged in it shows the login page, not a problem just continue the script. The current button i which is what i want to load automatically in the PHP file is located here, to test the functionalilty just click "Share" button in blue.. http://watch-movies-online.anyfilman...-Movie-17.html To summarise, i would like the above Javascript code to execute automatically upon pageload of this PHP file.. http://www.watch-movies-online.anyfi...p://google.com. If that could be done, and if this also is possible.. i would like for the "Share" button on the external page that is loaded from the Javascript code above to be clicked automatically so in effect when ever someone visits the PHP page after clicking "Click Here to Watch/Stream 2012 Online For Free" on this page it will automatically load the Facebook Share box, and automatically click the "Share" Button and then close the page if possible, but not required. Please feel free to ask any questions, i'll be happy to answer. Thanks in advance. Best Regards, Jonathan. I want to loop through a form containing various fields and replace them with values I have in a JS object. E.g. (1) <form id="theform"> <input type="text" name="field_1" value="" /> <input type="checkbox" name="field_2" value="" /> </form (2) object.field_1 = "Dave"; object.field_2 = ""; // empty as not checked, else holds value of checked one -- The problem is: what about checkboxes and <select> drop downs, and radios?? Is there a script like this around as I'm guessing this could be useful for Ajax to populate input boxes in some situations (depending on the content etc.) so I'm guessing I'm not the only one who needs this? i want to use arrays to populate an HTML list. I can populate the main list items but I can't seem to get the sub list items to work. Can anyone point out my mistake? Code: <HTML> <Body> <ul> <script> var pages = ["page1", "page2","page3"]; var subPages = ["sub1","sub2"]; for(var i = 0; i < pages.length; i++){ var page = pages[i]; document.write('<li>' + page + '</li>'); if (page == "page2"){ document.write('<ul>'); for(var i = 0; i < subPages.length; i++){ var subPage = subPages[i]; document.write('<li>' + subPage + '</li>'); } document.write('</ul'>); } } </script> </ul> </body> </HTML> I want to create a table in javascript with a predefined height and width and put html code in its td. I wanna know when i should stop writing html code when my table have reached the predefined height. Is there any way to do that? I started by doing this : var srcTable = document.createElement("table"); srcTable.border = 1; srcTable.borderColor = "Black"; srcTable.height = 768; srcTable.width = 1024; var tmpRow = null; var tmpCell = null; for (i = 0; i < rowCount; i++) { tmpRow = AppendRow(srcTable) for (j = 0; j < colCount; j++) { tmpCell = AppendCell(tmpRow); tmpCell.innerHTML = document.getElementById("div").innerHTML; tmpCell = null; } tmpRow = null; } The html code in "div" element is way big then 768 px. I wanna know how to loop over and break it when table reaches 768 px height. I would like to set up an image gallery so that when customer clicks on their chosen image, the image caption populates into the associated field in the form below the gallery, on the same page. Any way you know of to do this? I am not really a coder, I only know this and that, so examples or detailed instructions will be most helpful. Thanks very much. Hi all I have relatively easy task I need to accomplish but as per usual I have very little idea of how to do it. I have done a google search to no avail. Basically I need to: 1. Pull a value from inside a div Code: <div id="number">(invoice #1017)</span> 2. Populate a form input field with that value. Does this make sense? If not let me know if you need any more info. Thanks Ok so Im going to break down what Im trying to do and hopefully someone can point me to a possible solution without getting all technical. I have 2 div tags. the first is a content container more or less. the second is a container for a php built calender (using html tables). Basically when the page loads the php builds the calenders html table code. each td element has an onclick event handler. The goal is to have the javascript handler execute when any non empty cell is clicked (non empty being that it has a date associated with it and is not a blank space filler). This is the easy part. The hard part is that each calendar day potentially has certain information associated with it stored in a mysql database. Im wanting input fields within the first container div to autopopulate with the information from the database (if any) for whatever day is clicked. Ive search around and heard things like javascript cant do mysql queries directly, and heard mention of ajax. So im stumped as to how to accomplish this. whether i need an external php script for the queries (perhaps inside a php function that can return data to the javascript that calls it?), but if that is plausable would it cause page loads or the like to the user? i really dont want to have to learn ajax for this one page, just seems excessive, but i do need a way to make the content in the first div populate with the respective database data for the selected day on the calendar. any thoughts, comments, or solutions that dont involve yet another web language would be greatly appreciated. thanks
Hello all I am new here but this place looked great and like one of the only places where I could find the answer to my question. I have created a page which pulls search results from various sites using PHP. It displays each result in a row in a table upon running. I wanted to add a button saying "More information" at which point, a div would appear and load the associated link for that search result within an iframe within the newly appeared div. I've been able to get a div appear and disappear on button click but, I couldn't get it to dynamically load an iframe on click with the associated search results link. Any suggestions are greatly appreciated. Also let me know if you need more information before assisting. Thanks! Hey guys, I've never use JavaScript before so bare with me. But, I have a registration form, and I want to have a location field in it, and then a region field that changes depending on what the user set as their location. But, I cannot get it to work, and I have no idea of how to go about doing it. Here is the JavaScript I have been using so far: Code: function toggleTable(select) { if(select.value == "uk") { select.value = "uk"; document.getElementById("region2").style.visibility = "collapse"; document.getElementById("region1").style.visibility = "visible"; } else if(select.value == "usa") { select.value = "usa"; document.getElementById("region1").style.visibility = "collapse"; document.getElementById("region2").style.visibility = "visible"; } } and it does show the right region depending on what the user inputed, but when the page loads, all the fields show up until the user click on the location field, here is the code for that so you can test it out: Code: <tr><td>Location: </td><td><select name="location" onclick="toggleTable(this);"> <option value="none">Please Select One</option> <option value="uk">UK</option> <option value="usa">USA</option> </select></td></tr> <tr id="region1"><td>Region: </td><td> <select name="region"> <option value="uk1">uk1</option> <option value="uk2">uk2</option> </select></td></tr> <tr id="region2"><td>Region: </td><td> <select name="region"> <option value="usa1">usa1</option> <option value="usa2">usa2</option> </select> </td></tr> Any help at all please? |