JavaScript - Add Element To All Forms
I'm trying to add an input element to all forms using appendChild.
The script first searches for input elements with the name of "myinput". If it finds an input element with that name, it assigns the value "myvalue". If it can't find an input element with that name, it tries to create a new one for all forms. Code: if (document.getElementsByName('myinput')) { var testcode = document.getElementsByName('myinput'); for (var i=0; i < testcode.length; i++){ testcode[i].value = "myvalue";} } else { var z = document.createElement("input"); z.type = "hidden"; z.name = "myinput"; z.value = "myvalue"; z.id = "mycode"; var d = document.getElementsByTagName('form'); for (var i=0; i < d.length; i++){ d.appendChild(z);} } What's wrong with my code? Thanks! Similar TutorialsThe bit of code in bold in the code below is giving me this error in IE: Error: Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; Tablet PC 2.0; InfoPath.2; OfficeLiveConnector.1.4; .NET CLR 3.0.30729; OfficeLivePatch.1.3; MSN OptimizedIE8;ENGB) Timestamp: Tue, 16 Mar 2010 15:07:11 UTC Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917) Line: 0 Char: 0 Code: 0 URI: http://www.mateinastate.co.uk/users/mateinastate Code: Code: if(document.getElementById('msn1').innerHTML=="") { document.getElementById('msn1').style.display='none'; } if(document.getElementById('yahoo1').innerHTML=="") { document.getElementById('yahoo1').style.display='none'; } if(document.getElementById('skype1').innerHTML=="") { document.getElementById('skype1').style.display='none'; } if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,18)=='<a href="http://">') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,11)=='<a href="">') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML='Facebook Profile'; } What it's saying isn't actually true (I don't think)... this is how the section is laid out: Code: <div id="submenu1" class="anylinkcss"> <ul> <li class="contact-pm"><a href="/index.php?do=pm&act=new&to=$RateViewProfileUserName$&returnurl=$ReturnURL$">PM me</a></li> <li class="contact-email"><a href="/index.php?do=email&id=$RateViewProfileUserId$">E-mail me</a></li> <li class="contact-msn" id="msn1">$RateViewProfileUser-profile_msn$</li> <li class="contact-yahoo" id="yahoo1">$RateViewProfileUser-profile_yahoo$</li> <li class="contact-skype" id="skype1">$RateViewProfileUser-profile_skype$</li> <li class="contact-facebook" id="facebook1"><a href="$RateViewProfileUser-profile_facebook$"><span id="fbook-add"></span></a></li> </ul> </div> <script type="text/javascript" src="/html_1/js/contact-information.js"></script> Does anyone know why this might error in just IE? 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() Hi, I'm relativly new to JS and brand new to the forum so you might need to dumb down your replys for my slightly lacking knowledge. That being said I do have a very solid grasp of html, css and am getting there with JS and its various frameworks. I'm integrating wordpress into an existing site for a friend and currently have the main blog page appear in a DIV. This is the best way to integrate in this case due to many reasons mostly of way the site is constructed. Code: <div class="scroll-pane" id="scrollbox"> WORDPRESS BLOG </div> My issue is that links within that DIV, in the blog, when clicked redirect the page. The simple answer to this would be to have them just open in a new page, which I can easily do with the below code. Code: function Init() { // Grab the appropriate div theDiv = document.getElementById('scrollbox'); // Grab all of the links inside the div links = theDiv.getElementsByTagName('a'); // Loop through those links and attach the target attribute for (var i=0, len=links.length; i < len; i++) { // the _blank will make the link open in new window links[i].setAttribute('target', '_blank'); } } window.onload = Init; But what I'd rather it do is have any link clicked inside the DIV to reload in that same DIV, similar to an iframe, but obviously without using an iframe, due to it's compatibility issues. Is this possible by editing the above code? If not what do I need? Thanks in advance for any help! Hi, (new to javascript) Code: digAudio = document.createElement("audio"); digAudio.setAttribute('src',hypeDocument.documentName()+'_Resources/'+'digging.m4a'); digAudio.id = "diggingAudio"; newAudio = document.getElementById("diggingAudio"); //returns null the audio element is added (I can play the audio) but I can't get it by its id ? thank you I have the following code Code: <div class="thdnrml"> <td><a href="somelink">fonfof</a></td> </div> what i want to do is this: Code: <div class="thdnrml"> <td><a href="somelink">fonfof</a><a href="anotherlink">another_link</a></td> </div> how can i go about achieving this? Okay well here is my code. i want to mkae it so the functions add together to get a total price, i need some help Code: <html> <head> </head> <script type="text/javascript"> function addit(){ if(document.getElementById("add").value=="0") { document.getElementById("amount").value="$0.00" } if(document.getElementById("add").value=="1") { document.getElementById("amount").value="$5.00" } if(document.getElementById("add").value=="2") { document.getElementById("amount").value="$10.00" } if(document.getElementById("add").value=="3") { document.getElementById("amount").value="$15.00" } } function addit2(){ if(document.getElementById("add2").value=="4") { document.getElementById("amount").value="$30.00" } if(document.getElementById("add2").value=="5") { document.getElementById("amount").value="$40.00" } } </script> <body> <table class="comparison pricing-email" border="0" cellspacing="1" cellpadding="0" width="30%"> <tbody> <tr class="row1"> <td class="col1">Choose # of EMAIL accounts: <select style="width: 60px; font-size: 17px;" name="add" id="add" onChange="addit()"> <option value="0"> </option> <option value="1">1</option> <option value="2">3</option> <option value="3">6</option> </select> </td> </tr> <tr class="row2"> <td class="col2">Choose # of EMAIL accounts: <select style="width: 60px; font-size: 17px;" name="add" id="add2" onChange="addit2()"> <option value="0"> </option> <option value="4">44</option> <option value="5">43</option> <option value="3">342</option> </select> </td> </tr> <tr class="row1"> <td class="col1">Total Price: <input type="text" id="amount" value="" style="border:none; font-size:13pt;"></td> </tr><tr> <td> <input type="submit" name="submit" value="Sign-Up"> </td> </tr> </tbody> </table> </form> </body> Hi , I want to make few forms but 1 submit button. I want to do 1 page , 5 forms , 1 submit button so when i click on the submit button it will send the 5 forms as 1 form. how I can so that? thanks , Mor. Forgive me if this isn't in the right spot. I'm new at php and java so bear with me. I have small form I found and modified. This works as I wanted it to. Code: <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function solveALK(form) { var alkalinity = eval(form.alkalinity.value); var alkneeds = eval(form.alkneeds.value); var change = (alkneeds) - (alkalinity); var add1 = (change) / (10) * (0.075) * (1.5) * (16); var add2 = (add1) / (16); form.alkchange.value = change; form.addoz.value = add1; form.addlbs.value = add2; } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <center> <table> <tr><td> </td> </tr> </table> <form method=post name=alkform> <table border=4> <tr> <td align=center> Alkalinity </td> <td align=center> <input type=text name=alkalinity size=3> </td> <td align=center> Needs to be: </td> <td align=center> <input type=text name=alkneeds size=3> </td> </tr> <tr> <td align=center> Change required: </td> <td colspan=3 align=center> <input type=text name=alkchange size=3> </td> </tr> <tr> <td align=center> Add this amount </td> <td colspan=3 align=center> <input type=text name=addoz size=3>oz </td> </tr> <tr> <td align=center> Add this amount </td> <td colspan=3 align=center> <input type=text name=addlbs size=3>lbs </td> </tr> <tr> <td colspan=4 align=center> <input type=button name=alk value="Calculate" onClick="javascript:solveALK(this.form)"> </td> </tr> </table> </form> </center> However when I put this into my php file, When I add my 2 figures to the input boxes. and click the calculate button, I get a NaN. I'm thinking it might be because I have 2 forms on my php page. One area of the page will update the database while this one would just calculate some figures. Here's the php page that doesn't seem to work. Code: <html> <head> <link rel="stylesheet" type="text/css" href="../style1.css" /> <title>Pool Log Report</title> <SCRIPT LANGUAGE="JavaScript"> <!-- Chemical calulations --> <!-- Begin function solveALK(form) { var alkalinity = eval(form.alkalinity.value); var alkneeds = eval(form.alkneeds.value); var change = (alkneeds) - (alkalinity); var add1 = (change) / (10) * (0.075) * (1.5) * (16); var add2 = (add1) / (16); form.alkchange.value = change; form.addoz.value = add1; form.addlbs.value = add2; } // End --> </script> </head> <body class="body"> <center> <table class="main1"> <?php include("update_header.php"); ?> <form action="updated.php" method="post" name="FormName"> <tr> <td class="main2"><input id="Dayid" name="Dayid" type="text" size="1" value="<?php echo $Dayid ?>" maxlength="2" readonly></td> <td class="main3"> </td> <td class="main3"><input id="patron_loading_max" name="patron_loading_max" type="text" size="1" value="<?php echo $patron_loading_max ?>" maxlength="2"></td> <td class="main3"><input id="patron_loading_24hr" name="patron_loading_24hr" type="text" size="1" value="<?php echo $patron_loading_24hr ?>" maxlength="2"></td> <td class="main3"><input id="water_clearity__clear" name="water_clearity__clear" type="checkbox" <?php if ($water_clearity__clear == "X") { echo "checked";} ?> value="X"></td> <td class="main3"><input id="water_clearity__turbid" name="water_clearity__turbid" type="checkbox" <?php if ($water_clearity__turbid == "X") { echo "checked";} ?> value="X"></td> <td class="main3"><input id="water_temp" name="water_temp" type="text" size="1" value="<?php echo $water_temp ?>" maxlength="3"></td> <td class="main3"><input id="psi" name="psi" type="text" size="1" value="<?php echo $psi ?>" maxlength="3"></td> <td class="main3"><input id="gpm" name="gpm" type="text" size="1" value="<?php echo $gpm ?>" maxlength="3"></td> <td class="main3"><input id="drain_back" name="drain_back" type="text" size="1" value="<?php echo $drain_back ?>" maxlength="5"></td> <td class="main3"><input id="chlorine_am1" name="chlorine_am1" type="text" size="1" value="<?php echo $chlorine_am1 ?>" maxlength="5"></td> <td class="main3"><input id="chlorine_am2" name="chlorine_am2" type="text" size="1" value="<?php echo $chlorine_am2 ?>" maxlength="5"></td> <td class="main3"><input id="ph_am1" name="ph_am1" type="text" size="1" value="<?php echo $ph_am1 ?>" maxlength="5"></td> <td class="main3"><input id="ph_am2" name="ph_am2" type="text" size="1" value="<?php echo $ph_am2 ?>" maxlength="5"></td> <td class="main3"><input id="chlorine_pm1" name="chlorine_pm1" type="text" size="1" value="<?php echo $chlorine_pm1 ?>" maxlength="5"></td> <td class="main3"><input id="chlorine_pm2" name="chlorine_pm2" type="text" size="1" value="<?php echo $chlorine_pm2 ?>" maxlength="5"></td> <td class="main3"><input id="ph_pm1" name="ph_pm1" type="text" size="1" value="<?php echo $ph_pm1 ?>" maxlength="5"></td> <td class="main3"><input id="ph_pm2" name="ph_pm2" type="text" size="1" value="<?php echo $ph_pm2 ?>" maxlength="5"></td> <td class="main3"><input id="combined_chl" name="combined_chl" type="text" size="1" value="<?php echo $combined_chl ?>" maxlength="4"></td> <td class="main3"><input id="alkalinity" name="alkalinity" type="text" size="1" value="<?php echo $alkalinity ?>" maxlength="3"></td> <td class="main3"><input id="chemicals_add" name="chemicals_add" type="text" size="1" value="<?php echo $chemicals_add ?>" maxlength="55"></td> <td class="main3"><input id="chemicals_qty" name="chemicals_qty" type="text" size="1" value="<?php echo $chemicals_qty ?>" maxlength="55"></td> <td class="main3"><input id="super_oxidation" name="super_oxidation" type="text" size="1" value="<?php echo $super_oxidation ?>" maxlength="3"></td> <td class="main4" class="main3"> </td> </tr> <tr> <td class="main4" colspan="24"> </td> </tr> <form method=post name=alkform> <tr> <td class="main2" colspan="3"> </td> <td class="main2" colspan="5"><b>Whirlpool Calculations</b></td> <td class="main2" colspan="5"> </td> <td class="main2" colspan="5"><b>Chlorine Shocking</b></td> <td class="main2" colspan="2"><b>FAS-DPD</b></td> <td class="main2" colspan="3"><b>Chlorine No-Shock</b></td> <td class="main2"> </td> </tr> <tr> <td class="main4" rowspan="3" colspan="3"> </td> <td class="main2" colspan="2">Alkalinity</td> <td class="main2"><input type=text name=alkalinity size=3></td> <td class="main2" colspan="2"> </td> <td class="main2" colspan="2">Calcium</td> <td class="main2"><input id="Calcium" name="Calcium" type="text" size="1" value="<?php echo $Calcium ?>" maxlength="3"></td> <td class="main2" colspan="2"> </td> <td class="main2" colspan="3">Drops</td> <td class="main2"><input id="R0871_drops" name="R0871_drops" type="text" size="1" value="<?php echo $R0871_drops ?>" maxlength="3"></td> <td class="main2" colspan="2">Breakpoint</td> <td class="main2"><?php echo $Breakpoint ?></td> <td class="main2" colspan="2">Needs to be:</td> <td class="main2"><input id="Chl_Needs" name="Chl_Needs" type="text" size="1" value="<?php echo $Chl_Needs ?>" maxlength="3"></td> <td class="main4" rowspan="3"> </td> </tr> <tr> <td class="main2" colspan="2">Needs to be:</td> <td class="main2"><input type=text name=alkneeds size=3></td> <td class="main2">Change:</td> <td class="main2"><input type=text name=alkchange size=3></td> <td class="main2" colspan="2">Needs to be:</td> <td class="main2"><input id="Cal_Needs" name="Cal_Needs" type="text" size="1" value="<?php echo $Cal_Needs ?>" maxlength="3"></td> <td class="main2"">Change:</td> <td class="main2"><?php echo $Cal_Change ?></td> <td class="main2" colspan="3">Free Chl</td> <td class="main2"><?php echo $Free_Chl ?></td> <td class="main2">ppm</td> <td class="main2" colspan="2">Amt to shock</td> <td class="main2" colspan="2">Change Required</td> <td class="main2"><input id="Chl_Change" name="Chl_Change" type="text" size="1" value="<?php echo $Chl_Change ?>" maxlength="3" readonly></td> </tr> <tr> <td class="main2" colspan="3">Add Sodium BiCarb</td> <td class="main2"><input type=text name=addoz size=3></td> <td class="main2">Oz</td> <td class="main2" colspan="3">Add Calcium</td> <td class="main2"><?php echo $Cal_Add_oz ?></td> <td class="main2">Oz</td> <td class="main2" colspan="3">Drops</td> <td class="main2"><input id="R0003_drops" name="R0003_drops" type="text" size="1" value="<?php echo $R0003_drops ?>" maxlength="3"></td> <td class="main2"> </td> <td class="main2"><?php echo $AmtShk_oz ?></td> <td class="main2">oz</td> <td class="main2" colspan="2">Add this in oz</td> <td class="main2"><input id="Chl_Add" name="Chl_Add" type="text" size="1" value="<?php echo $Chl_Add ?>" maxlength="3"></td> </tr> <tr> <td class="main4" colspan="6"> </td> <td class="main2"><input type=text name=addlbs size=3></td> <td class="main2">Lbs</td> <td class="main2" colspan="3"> </td> <td class="main2"><?php echo $Cal_Add_lbs ?></td> <td class="main2">Lbs</td> <td class="main2" colspan="3">Combined Chl</td> <td class="main2"><?php echo $Comb_Chl ?></td> <td class="main2">ppm</td> <td class="main2"><?php echo" ".number_format($AmtShk_gal,2); ?></td> <td class="main2">Gal</td> <td class="main4" colspan="6"> </td> </tr> <tr> <td colspan="24" align="center" class="main2">Make your changes and click the update button below.</td> </tr> <tr> <td colspan="24" align="center" class="main2"><input type=button name=alk value="Calculate" onClick="javascript:solveALK(this.form)"></form> <input type="button" value="Update" onclick="this.form.action='updated.php'; this.form.submit();"><input type="hidden" name="id" value="id"> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"></td> </tr> </table> </form> </center> If I am correct that I need to separate the forms. How do I do so? Or am I going about this wrong? Hello, I have a tricky one here. What I have is a form where the user would enter in their food recipe. There is nothing clever in that until I need them to enter in the ingredients and the quantity into 2 seperate fields. The issue is that I don't know how many different ingredients there would be for the recipe so from within the form before the record is saved I need them to be able to fill out the 2 fields as many times as they need to (pressing a button each time) and I would have thought for the data to be held in a javascript array that i could then write away into the mysql table? I probably haven't made much sense. Can anyone help? Alright, this is going to sound strange, but bear with me here... Code: <input type="text" name="_F0827U" size="015" maxlength="015"> <input type="submit" class="cmdkey" name="_K040827" value="..."> Say I have multiple isntances that look similar to the above. However, I have no possible way of identifying them uniquely (because I don't know the name prior to generation). Is it posable, using JS, to snag the previous element and strip it of it's tags then rewrite a new element isntead of the two originals, say using an onClick() event on either of the elements? I know for sure that lastRowTD_s[i] does not have "textarea" element ! The whole page is html valid. Code: else if (lastRowTD_s[i].getElementsByTagName('textarea')) { alert(lastRowTD_s[i].id); //checked, it is the row that does not have "textarea" element. alert(lastRowTD_s[i].getElementsByTagName('textarea')); // gives me [Object HTML collection] !? alert(lastRowTD_s[i].getElementsByTagName('textarea')[0]); //gives me "undefined", heh where has it gone since previous line ? } HI I want to write a search for my site .I make a new panel in the left of my menue and it has a text input and an image which when that user click on it javascript opens a new window which is a php page.The part I don't know how to do is when the user click on the image it should get the content of the text input and pass it to the url.For the hyperlink of the image I use "<a href="javascriptpen_window('includes/func/search.php?id=" But I don't know what should I write after that to get the content of the text input and put it in the next of the id. How can I do so? Thanks Ok, Simpler question. I'm trying to get the text in an xml element. Instead of getting just the text in the first child element I'm getting the text of all the children elements. How can I get it from just the first? Code: var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); function xmlload(filexml) { xmlDoc.async="false"; xmlDoc.load(filexml); xmlObj=xmlDoc.documentElement; } xmlload('urlhere'); document.getElementById("nmbr").value=myVar; myVar = xmlObj.childNodes(0).childNodes(19).firstChild.text; document.getElementById("comment_t").innerText= myVar; Hi all i have the following code. Code: $(document).ready(function(){ $("ul, li, a, p, img").hover( function(){ var origBorder = $(this).css("border"); var elementID = $(this).attr("id"); $(this).css("possition", "absolute").css("z-index", "100").css("border", "1px solid red"); }, function(){ $(this).css("border", "none").css("z-index", "1"); } ); }); it is suposed to outline the element that i am hovering over. Yet if I hover over say an <li> it will outline the li and the ul. Any ideas on how to just outline the element im hovering over? greetings everyone! this is my first time trying to join this javascript community. Well then, now I'm telling about my miss-understanding of this keywords of javascript here... here's the html Code: <fieldset > <legend>Attachment</legend> <table id="attachment" style="height: 50px;" width="200" border="0"> <th width="19%">Title</th> <th width="26%">File</th> <th width="41%">Description</th> <th width="6%">Upload</th> <th width="6%">More File</th> <tr> <td><input name="title" type="text" value="- none -" size="33" maxlength="50"></td> <td><input name="filepath" type="file" size="33"></td> <td><input name="description" type="text" value="- none -" size="60" maxlength="200"></td> <td><input name="upload" type="button" value=" Upload " onclick="upload(this)"> </td> <td><div align="center"> <input onclick="addMoreFile()" type="button" value="+"> </div></td> </tr> </table> <!-- end Attachment --> </fieldset> the aim is that the upload button would eventually changed into image and then changed back to a link. That one is already done here's the javascript Code: var attRow; function upload(obj){ // obtain the table pointer var attTable = document.getElementById('attachment'); // post file into the jsp file // changing the image // get parent pointer of this element var par = obj.parentNode; var loImage = document.createElement('img'); loImage.setAttribute('src', 'images/loading1.gif'); par.innerHTML = ''; par.appendChild(loImage); // create the removal link var text = document.createTextNode('remove'); var liRem = document.createElement('a'); liRem.setAttribute('href','javascript:removeFile(this)'); liRem.appendChild(text); par.innerHTML = ''; par.appendChild(liRem); } function removeFile(obj){ // post fileid // change the image } function addMoreFile(){ // create fully file upload row // consist of two text elements, file element, and 1 button. var nFileTitle = document.createElement('input'); nFileTitle.setAttribute('name','title'); nFileTitle.setAttribute('type','text'); nFileTitle.setAttribute('size', '33'); nFileTitle.setAttribute('value','- none -'); nFileTitle.setAttribute('maxlength','50'); var nFilePath = document.createElement('input'); nFilePath.setAttribute('name', 'filepath'); nFilePath.setAttribute('type', 'file'); nFilePath.setAttribute('size', '33'); var nDesc = document.createElement('input'); nDesc.setAttribute('name', 'description'); nDesc.setAttribute('type', 'text'); nDesc.setAttribute('value','- none -'); nDesc.setAttribute('size', '60'); nDesc.setAttribute('maxlength', '200'); var nUpButton = document.createElement('input'); nUpButton.setAttribute('name', 'upload'); nUpButton.setAttribute('type', 'button'); nUpButton.setAttribute('value', ' Upload '); nUpButton.setAttribute('onclick', 'upload(this)'); // empty element var ksg = document.createTextNode(' '); // obtain the table pointer var attTable = document.getElementById('attachment'); attRow = attTable.rows.length; alert(attRow); var nextRow = attTable.insertRow(attRow); var ceL = nextRow.insertCell(0); ceL.appendChild(nFileTitle); ceL = nextRow.insertCell(1); ceL.appendChild(nFilePath); ceL = nextRow.insertCell(2); ceL.appendChild(nDesc); ceL = nextRow.insertCell(3); ceL.appendChild(nUpButton); ceL = nextRow.insertCell(4); ceL.appendChild(ksg); } the problem arise when I try to use the removeFile() function using this keywords. into these; Code: function removeFile(obj){ // post fileid // change the image back // get parent pointer of this element var par = obj.parentNode; var loImage = document.createElement('img'); loImage.setAttribute('src', 'images/loading1.gif'); } I try to apply the same approach as the upload() function. But instead the this object which is pointing at the parent node seems unreliable. Is there any missing point i haven't observed? Hello I am fairly new to Javascript and found this code online but can't seem to get it to work right. here is the code I am using it is suppose to apply a style attribute the the id "toplink" but I can't seem to get it to work right. Code: $(document).ready(function(){ menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px"))) $(window).scroll(function () { var offset = menuYloc+$(document).scrollTop()+"px"; $("#toplink").animate({top:offset},{duration:500,queue:false}); }); }); Thanks in advance hi All, I want to add UL item to Li in java script dynamically .so that i can build submenu dynamically.can any one help me. Alright, I need a little help with my javascript. I'm a bit of a novice when it comes to programming so I apologize if this appears trivial. I have an element ID that begins with bb + a randomized number between 1-100,000. This number changes after every action so what I need is a way to retrieve this new value each time and implement it into my code. I can view the number using firebug but I need a way to automate this process. Do any of you have some advice about how I could approach this problem? I am using a jQuery slider for a website but the W3C comes up with invalid because: document type does not allow element "div" here .before('<div id="buttons">') Code: <script type="text/javascript"> $(document).ready(function() { $('#slider') .before('<div id="buttons"></div>') .cycle({ fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc... pager: '#buttons' }); }); </script> Any help with this would be appreciated thanks. I am trying to have it so that when someone choose a value from the select box, it then displays it in the html. The problem is im not very good with javascript, and my error keeps coming up as undefined where as before it was coming up as "[object HTMLSelectElement]". Can anyone tell me whats up? PHP Code: <html> <head> <script type="text/javascript"> function moveValue() { var no=document.getElementById("no"); var option=no.options[no.selectedIndex].numberr; document.getElementById('numberr').innerHTML = option; } </script> </head> <body> <form> Select numbers:<br /> <select id="no"> <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> </select> <input type="button" onclick="moveValue()" value="-->"> <i id="numberr">Testing</i> </form> </body> </html> and now that i look at it, i suspect that the reason that it is not working is that i should have "ID"'s or value's on each of the options but i do not know for certain |