JavaScript - Need A Small Help -- Dropdownlist To Xml File
Hey guys
I need a small help. I am new to Javascript. I want to save data from dropdownlist to XML file. Save function is working but I dont know how to load data list from dropdown to xml file. I can do with input element but dont know how to work with dropdown element. How to do this? Look at my codes below: HTML markup (index.html): FOCUS ON RED <body> <form name="reg" action="index.html" method="get"> Name: <input type="text" name="name_input" /> Pass: <input type="text" name="pass_input" /> <select id="language"> <option name="select_afrikaans">Afrikaans</option> <option name="select_english">English</option> </select> <br /> <input type="button" value="SAVE" onclick="javascriptk_click();" /> </form> </body> Javascript: function ok_click() { var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.load("data.xml"); if (xmlDoc.readyState == 4 && xmlDoc.parseError.errorCode == 0) { var root = xmlDoc.documentElement; var _input_name = xmlDoc.createTextNode(document.reg.name_input.value); var _input_pass = xmlDoc.createTextNode(document.reg.pass_input.value); var _select_afrikaans = xmlDoc.createTextNode(document.reg.select_afrikaans.value); var _select_english = xmlDoc.createTextNode(document.reg.select_english.value); var input_name = xmlDoc.createNode(1, "USER", ""); var input_pass = xmlDoc.createNode(1, "PASS", ""); var input_select = xmlDoc.createNode(1, "LANGUAGE", ""); input_name.appendChild(_input_name); input_pass.appendChild(_input_pass); select_afrikaans.appendChild(_select_afrikaans); select_english.appendChild(_select_english); var cust = xmlDoc.createNode(1, "CUST", ""); cust.appendChild(input_name); cust.appendChild(input_pass); cust.appendChild(select_afrikaans); cust.appendChild(select_english); root.appendChild(cust); SaveXML(xmlDoc, "data.xml"); alert("Save!"); } } // It is working fine function SaveXML(xmlDoc, filename) { var outputXML = new String(xmlDoc.xml); var mfObj = new ActiveXObject("Scripting.FileSystemObject"); var absPath = getPath(); var file = mfObj.CreateTextFile(absPath + filename, true); file.Write(outputXML); file.Close(); } //it is working fine function getPath() { var path = document.location; var str = new String(path); var end = str.lastIndexOf("/"); var absolutePath = str.substring(8, end) + "/"; absolutePath = absolutePath.replace(/ /g, " "); return absolutePath; } XML File: <?xml version="1.0"?> <DATA> <CUST> <USER>natalie</USER> <PASS>80</PASS> </CUST> ........ here should display xml data from dropdown list.....how? </DATA> Your help would much appreciated. Thank you very much Regards Natz Similar TutorialsHi, i need a dropdownlist in javascript... in which the dropdown list contains the names.... the names should come from database.... by this query "select distinct c_main from kpitable" can some body help me... Hello guys, How to populate array from dropdownlist? I've tried like this var array = new array(); var d = document.getElementById("DropDownListl"); for (var i = 0; i < d.options.length; i++) { array[i] = d.options[i].value; } Thank you Code: I have to create two dropdownlists that are dependent In my first select tag there are 4 selections ,,, year,quarter,month and week. and in second select it should automatically populate..If user select year from first select in second select values should be 1 to 365.. if quarter values in second select(dropdown) should be 1 to 4. if month 1 to 12 and if week is selected 1 to 7.. can anyone help me to achieve this.. I will post that code and please help me to resolve this error as iam naive user to javascript.. <select id="user_defn_uom" name="user_defn_uom" onchange="alert(this.options[this.selectedIndex].text)" align="center"> <option selected value=""> <option value="Yearly">Yearly <option value="Quarterly">Quarterly <option value="Monthly">Monthly <option value="Weekly">Weekly </td> <td>. <select name="user_defn_day" align="center"> <option selected value=""> <script type="text/javascript"> alert(this.options[this.selectedIndex].text) for (var i = 1; i <=366; i++) { document.write('<option value="' + i + '">' + i + '</option>'); } </script> </select> i have a dropdownlist with some values,ex: One, Two and Three; One being the default value selected on load of dropdown list. When I select Two or Three, there is onselectedchange event fired and I can write custom code in handler. But I also want to do some custom handling when page is loaded and user justs clicks on default value of "One". I want to take an action when user clicks on default value, "One" of dropdwn. any suggestions/ideas? Hi, I have this web browser which opens up a website that has a drop down list showing values that the user can select. And when I the firebug to inspect the elements in the page, what shows in the inspection window is this: Code: <select id="instance2" name="instance2"> <option value="0">All instances</option> <option value="1">Item0</option> <option value="2">Item1</option> <option value="3">Item2</option> . . . <option value="23">Item22</option> What I'm supposed to do is to get the values and update them automatically to the database. I'm actually using HtmlUnit to do this project, and I've heard how I can use getElementById() to get the values. But I don't know how to start. I'm a beginner so I might need a lot of help on this matter. Help is kindly appreciated. Thanks. Hi Experts, i have 2 JS array and i need to have dependency between them knowing that 1st Array has parent element of the 2nd one. i.e ARRAY1 ID VAL ID2 2 Dep1 10 3 Dep2 20 4 Dep3 30 ARRAY2 ID VAL ID2 PARENT 20 team1 11 10 21 team2 12 10 22 team3 13 20 23 team4 14 30 i need to have two different DDL's where when i choose VAL = Dep1 on ARRAY1 , i should see on the 2nd DDL only elements with parent corrsponding to Dep1 ( PARENT =10). how this can be possible thanks Hi All. I have a dropdown list on a web form containing dates. My Question: How can I call data for that selected item(date) from a MySQL database and display it to the user? And more specifically, if that selected date has no data in the data base, I want to be able to display that as well. I'm looking for a Javascript solution, and if possible a php solution. Thank You! Hi everyone, now I need to add items into a dropdown list, and the items would be sorted alphabetically and it does not allow duplicate items to be added. Can anyone help take a look and see what's wrong with my code? Javascript Code: function addAnotherOption() { var newItem = document.getElementById("Text44"); if (!newItem.value == "") { var answer = confirm ("Are you sure you want to add? ") if (answer)//if answer is true { var lst = document.getElementById('comboBox'); // listbox control id // Now we need to create a new 'option' tag to add to MyListbox var newOption = document.createElement("option"); newOption.value = newItem.value; // The value that this option will have newOption.innerHTML = newItem.value; // The displayed text inside of the <option> tags for (var i = 0; i < lst.options.length; i++) { arrTexts = lst.options[i].text; if (arrTexts.toLowerCase() == newItem.toLowerCase()) { alert ("That option is already included in the list - please enter another item."); return false; } else { // Finally, add the new option to the listbox lst.appendChild(newOption); //sort items in listbox in alpha order arrTexts = new Array(); for(i=0; i<lst.length; i++) { arrTexts[i] = lst.options[i].text; } arrTexts.sort(); for(i=0; i<lst.length; i++) { lst.options[i].text = arrTexts[i]; lst.options[i].value = arrTexts[i]; } } } } } else { if(newItem.value == "") { alert("Key something to textbox please."); } else alert("Cancelled."); } } HTML Code: <input id="Text44" type="text" /> <input id="Submit22" type="submit" value="Add" onclick="addAnotherOption()" /><br /> <select name="combo" id= "comboBox" style="width: 323px"> <option value="H">Hearts</option> <option value="D">Diamonds</option> <option value="C">Clubs</option> <option value="S">Spades</option> </select> Hi Peers, i have a Drop down list with 10 choices (skillset). users must choose one skillset and the corresponding level (beginer/intermediate/master). ( they have to do this 10 times for all the sillsets) what i want is : 1 - i need to show up only one record (dropdowanlist) with level then have a button to add new skill and level if required 2- then when they choose the 1st skill from the dropdown , this one will not show up on the 2nd choice dropdown. is it possible any help ? thanks guys Hey all, I have this code on my site that simply says if we are open or not. Code: <script language="Javascript"> <!-- /* Credit must stay intact Visit java-scripts.net or http://wsabstract.com for this script */ now = new Date if (now.getHours() <21) { document.write("We are Currently : Open") } else if (now.getHours() <9) {* * document.write("We are currently : Closed")} else { * *document.write("We are currently : Closed")} //--> </script> I wish to know how I can change this code so that I can add some colour and change the size of the font. Any help would be great. Hello. I have created a button so that when a person click it, it should turn the text into Bold font weight - Fortunately it works, However i tried adding an alternative which is when the text is already turned into Bold font weight the person could click the button in order to switch the text into normal mode, simply cancel the Bold - Unfortunately it doesn't work at all - Can Some one review my little script and help me solve it out ? PHP Code: <script type="text/javascript"> function bold(id) { if (document.getElementById) { document.getElementById(id).style.fontWeight = 'bold'; } else if (document.all) { document.all[id].style.fontWeight = 'bold'; } } //@@@@@@@@@@@(Now the rest of the code down bellow is what i have added so that i could click an cancel the bold mode or (document.all) { document.all[id].style.fontWeight = 'normal'; } </script> and that's the image code : PHP Code: <img src="Bold.bmp"width="42" height="39" title="Bold Font" onclick="bold('bodytext')" style="cursor:pointer;" /> Hello all i've made Contact me form with JS validation , my qs is : i do not want the alert pop up small window a post text the alert in DIV i have read it's innerHTML here the JavaScript Code: function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; } // Vadate name function checkname (strng){ var error=""; if (strng == ""){ error = "Please Enter your name." } return error; } //Vadate last name function checkprename (strng){ var error=""; if (strng == ""){ error = " Please Enter your name" } return error; } function checkPhone (strng) { var error = ""; if (strng == "") { error = "Vous n'avez pas inscrit un numero de telephone.\n"; } var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters if (isNaN(parseInt(stripped))) { error = "vous entrez le numero de telephone errone."; } if (!(stripped.length == 10)) { error = "vous entrez le numero de telephone errone.\n"; } return error; } //Validate Email function checkEmail (strng) { var error=""; if (strng == "") { error = "Vous n'avez pas entre une adresse email.\n"; } var emailFilter=/^.+@.+\..{2,3}$/; if (!(emailFilter.test(strng))) { error = "S'il vous plait entrer une adresse email valide.\n"; } else { //test email for illegal characters var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (strng.match(illegalChars)) { error = "L'adresse email contient des caracteres illegaux.\n"; } } return error; } Now here in html Code: function checkWholeForm(theForm) { var why = ""; why += checkname(theForm.name.value); why += checkprename(theForm.prename.value); why += checkEmail(theForm.Email.value); why += checkPhone(theForm.Phone.value); if (why != "") { var leDiv = document.getElementById('errormsg'); var nouveauDiv = document.createElement('div'); var divIdName = 'errormsg'; nouveauDiv.setAttribute('id',divIdName); nouveauDiv.innerHTML = "u had Enter wrong information bla bla"; leDiv.appendChild(nouveauDiv); var nouveauDiv2 = document.createElement('div'); var divIdName = 'errormsg'; nouveauDiv2.setAttribute('id',divIdName); nouveauDiv2.innerHTML = ' '; leDiv.appendChild(nouveauDiv2); return false; } return true; } MY qs is how to let the innerHTML past past each error from the validate.js file which i call it erorr i mean near to input filed of phone it will be div id erorrmsg and in this div will past the error from the validate.js which it code from my start of this post thanks for advance Hi all, I got a small problem. Please help me. Below is the code for toggle text. My problem is Whenever I click Toggle div 1 a Contents of div1 opens. I want a code to hide Contents of div1 when I click Toggle div 2(Shows only Contents of div2) or Toggle div 3 (Shows only Contents of div3) and vice versa. Code: <div align="left" id='div1' style='display:none'>Contents of div1</div> <div align="left" id='div2' style='display:none'>Contents of div2</div> <div align="left" id='div3' style='display:none'>Contents of div3</div> <button onclick="toggle(1)">Toggle div 1</button> <button onclick="toggle(2)">Toggle div 2</button> <button onclick="toggle(3)">Toggle div 3</button> <script> function toggle(x){ var divx = document.getElementById('div'+x) if (divx.style.display == 'none') { divx.style.display = 'block' } else { divx.style.display = 'none' } } </script> I have a form and the Js validation wont work on it. Here is the html PHP Code: <form name="frm" action="index.php" method="POST" onsubmit="return validateForm();"> <table width="100%" border="0" cellspacing="2" cellpadding="3" class="mainForm"> <tr> <td class="normalText" align="left" style="padding:0px 0px 0px 33px"> <table border="0" cellspacing="3" cellpadding="2"> <tr> <td class="normalHeading" colspan="2" style="padding-bottom:6px"> <div id="error_msg" class="txtErrorMsg" align="center"></div> <!-- <?php echo "<p id=\"error_msg\">".$message."</p>"?> --> </td> </tr> <tr > <td class="normalText" width="30%">First Name</td> <td><input type="text" name="firstName" id="firstName" class="input1" style="width:195px" maxlength="10"/></td> </tr> <tr> <td class="normalText">Last Name</td> <td><input type="text" name="lastName" id="lastName" class="input1" style="width:195px" maxlength="10"/></td> </tr> <tr> <td class="normalText">Mobile</td> <td><input type="text" name="mobile" id="mobile" class="input1" style="width:195px" maxlength="10" onkeypress="return fnIsIntNumber(event,this);"/></td> </tr> <tr> <td class="normalText">Email</td> <td><input type="text" name="email" id="email" class="input1" style="width:195px" onblur="IsEmail(this.vlaue)"/></td> </tr> <tr> <td class="normalText">Comments</td> <td> <textarea name="comments" id="comment" cols="22" rows="3" ></textarea> </td> </tr> <tr> <td class="normalText"> </td> <td valign="middle"><input class="send" type="image" value='submit' src="images/submit.gif" name="submit" /></td> </tr> </table> </td> </tr> </table> </form> and here is the JS PHP Code: var $j = jQuery.noConflict(); function isValidEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); } function validateForm(){ var firstName; var lastName; var email; var mobile; var comment; var error; firstName = $j('#firstName').val(); lastName = $j('#lastName').val(); email = $j('#email').val(); mobile = $j('#mobile').val(); comment = $j('#comment').val(); if(firstName=='' || firstName.length < 3){ error = 'Please Enter Your First Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(lastName=='' || lastName.length < 3){ error = 'Please Enter Your Second Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(email=='' || !isValidEmail(email)){ error = 'Please Enter Your Correct Email'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } //mob //$jmob_pattern = '^\d{10}$j'; if(mobile.length != 10 || isNaN(mobile)){ error = 'Please Enter Your Correct Mobile Number'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(comment.length < 10){ error = 'Please Enter A Comment More Than 10 Characters'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } return true; } Can anybody tell me what the problem is Hi all, I found a small fading script online which suits my needs though I need some help changing it around a bit as it seems to only work once in a page (i.e. a second occurance of the code doesn't work though the first one continues). Also, I'm not quite sure how to put it into a .js external page and then call the specific function as many times as I want in the body and have it all work. Please advise on this issue (i.e. Putting the code in an external file and then calling the fadeIn() function as many times as I want in the body). Thanks. BTW, the concept is a fixed imaged with the js fading another image over the top of that first image in and out over and over again. All the images and application of the js will be the same for all occurrences on the page (don't know if that's relevant to the solution I'm asking for but throwing it in there just in case). Here is the code: Code: <html> <body style="background:#000;"> <div style="float:left;"> <img style="float:left;" id="me" src="fade_arrow2.png"/> <img style="float:left;margin-left:-44px;" src="fade_arrow1.png"/> <script type="text/javascript"> var element = document.getElementById('me') ; var duration = 4000; /* 1000 millisecond fade = 1 sec */ var steps = 20; /* number of opacity intervals */ var delay = 5000; /* 5 sec delay before fading out */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ fadeIn(); </script> </div> </body> </html> I have a piece of code that pulls reviews and allows a business owner to drop the reviews on to their website. I need to limit the number of reviews and ideally I'd like to do that with just the snippet the biz owner drops into their site. Is this possible? Here's a sample of the code: <div id="repagent_reviews"></div><script type="text/javascript" src="http://awebsite.com/anotherwebsite/wp-admin/admin-ajax.php?action=repagent_reviews_js&id=1182"></script> thanks! confused Hello to all, I want to fuse these 2 scripts but don't know how: First script chains 2 selects DEMO: http://www.plus2net.com/php_tutorial/dd.php Second retains and displays values of form input fields if page refreshes DEMO: http://www.plus2net.com/php_tutorial/page-reload.php Code: <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val; } </script> I want to FUSE with this one: Code: <script type="text/javascript"> function reload() { var val1=document.form1.fname.value ; var val2=document.form1.mname.value ; var val3=document.form1.lname.value ; //// For radio button value to collect /// for(var i=0; i < document.form1.type.length; i++){ if(document.form1.type[i].checked) var val4=document.form1.type[i].value } self.location='validation4.php?fname=' + val1 + '&mname=' + val2 + '&lname=' + val3 + '&type=' + val4; } </script> first of all, hello all i found this forum while running out of ideas and being extremely desperate to fixing a probably small javascript error in a script. the script is supposed to open a small form window that allows the user to input an email address and update it to proceed. the form item is initially unchecked, but as the user clicks it and enter his email address, it updates the value of the email address and the box becomes "checkable". the problem is that with both IE and firefox, the box doesn't close again, doesn't get checkable and basically doesn't work. in the firefox debugging console, I found the following error: Quote: Error: document.getElementById(input_array[i]) is null Source File: sell_item.php Line: 1106 does anyone have an idea what could be wrong? the part responsible in the javascript for this section is: Code: <script language="javascript"> function pg_popup_open(id) { if (document.getElementById(id).style.display == 'block') { document.getElementById(id).style.display = 'none'; } else { document.getElementById(id).style.display = 'block'; } return false; } function pg_update_settings(id, input_array) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url = '' + 'ajax_files/direct_payment_box.php'; var action = url + '?id=' + id + '&user_id=' + 100001; var chk_disabled = false; for ( var i in input_array ) { action += '&' + input_array[i] + '=' + document.getElementById(input_array[i]).value; if (document.getElementById(input_array[i]).value == '') { chk_disabled = true; } } xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { var response = xmlHttp.responseText; } }; xmlHttp.open("GET", action, true); xmlHttp.send(null); document.getElementById('checkbox_' + id).disabled = chk_disabled; if (chk_disabled == true) { document.getElementById('checkbox_' + id).checked = false; } document.getElementById(id).style.display = 'none'; return false; } </script> and the html code that is supposed to pop up the box is: Code: <input type="checkbox" name="payment_gateway[]" id="checkbox_pg_paypal" value="1" disabled> <span class="contentfont"><a href="javascript:;" onclick="pg_popup_open('pg_paypal');">PayPal</a></span> <script language="javascript"> var array_pg_paypal = new Array(); array_pg_paypal[0] = 'pg_paypal_email';</script> <div class="smallfont"><b>PayPal Email Address</b><br> <input type="text" name="pg_paypal_email" id="pg_paypal_email" value="" /></div> <div align="right"><input type="button" value="Proceed" onclick="pg_update_settings('pg_paypal', array_pg_paypal);" /></div> i understand this is asking a lot, but if someone has a spare second that is a javascript guru, i promise i will name my first born after you!! lol ok i am trying to make a countdown timer from 20 seconds when i click start where am i going wrong with this Code: <html> <head> </head> <body> <script type="text/javascript"> function timer() { var milisec=0 var seconds=20 document.counter.d2.value=20 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1){ milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",100) display() }} </script> <form name="counter"> <center> Text Timer<br> <input type="text" size="30" name="d2"> <br> <input type="button" onclick="timer()" value="click me to start"> </center> </form> </body> </html> sorry i think this is in the wrong section...how do i remove Hi, I know this works in principle as I have used it successfully on other pages I am using so I must have a typo or some other small mistake, I have gone over and over it, taken things out, put them back in and I can't for the life of me work out where my mistake is. Another pair of eyes would certainly be appreciated. My code is: Code: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function (){ $('#submitnewfestival').click(function(){ var data = $('#publicnewevent').serialize(); $.post ('insertPublicEvent.php',data, function(){ alert("Thank you for adding an event to our calendar."); $('#publicnewevent').each (function(){ this.reset(); }); }); return false; }); }); </script> <form action="" name="publicnewevent" id="publicnewevent" method="post" autocomplete="off" > <label class="two">Dress Code:</label> <input type="text" class="input" name="dresscode" id="dresscode" value="Enter Dress Code" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Enter Dress Code':this.value;" size="100" /> <br /> <br /> <input type="button" name="submitnewfestival" id="submitnewfestival" value="Submit" /> </form> The insertPublicEventForm.php works as I have tested it without JQuery as a direct post. This is a heavily reduced version of the form, but even like this I can not get it to work. |