JavaScript - Row Highlighting - I'm So Lost, And Losing More And More Hair
Code:
// Code for alternating row colors on data tables, but NOT every table.... just ones with classname="altRows" // Note: rowID comes from the JIT Variable: &&_sflalt // Note: This function is called in ovject group: *TR in the MLS Syntax File function stripeRows(rowVar) { // Need to create a var for uniquely identifying the highlighted rows var rowID = 0; // Begin the checking and writing of the HTML data if (rowVar == '') { var html = "<tr>"; document.writeln(html); } else if (rowVar == '0') { var html = "<tr class=\"rowEven\" id=\"evenRow"+rowID+"\" onmouseover=\"highlightRow('over', 'evenRow"+rowID+"');\" onmouseout=\"highlightRow('out', evenRow"+rowID+"');\">"; document.writeln(html); rowID++; } else if (rowVar == '1') { var html = "<tr class=\"rowOdd\" id=\"oddRow"+rowID+"\" onmouseover=\"highlightRow('over', 'oddRow"+rowID+"');\" onmouseout=\"highlightRow('out', oddRow"+rowID+"');\">"; document.writeln(html); rowID++; } else { var alertText = "Something went wrong with alternating row color in datasets - The function broke. Please jot down a note as to what you were doing when this dialogue box poped up, and let American Health Care Software know \n\n\n ATTN: Pat Litke"; parent.showDialog('Broken Function',alertText,'prompt'); } } // Function for modifying class attrbutes for row highlighting.. // This function will allows the currently moused-over row to highlight a different color based on its ID function highlightRow(option, theRowID) { var row = document.getElementById(theRowID); if(option == 'over') { row.className = 'rowOver'; } if(option == 'out') { row.className = 'rowEven'; } else if(option == 'in') { row.className = 'rowOdd'; } else { } } Can someone help? I can't figure out why this isn't working the way that I'm logically seeing it... The alternate rows highlight works fine, but the mouseover and mouseout events fail miserebly... When a page loads, regardless of where i mouse over, only the top two rows color in with the mouseOver color. They also don't revert to original coloring. Where am I going wrong? Note: I apologize if it's something little that I'm missing... I'm still new to js Similar Tutorialshttp://whitelemondesigns.com/test/about.html I can't for the life of me figure out where I'm going wrong with the scroll bar... I think I've got all the html and css correct, I have to assume there's a javascript error but I can't find it... could I have a javascript conflict? If you guys have any insight I would appreciate it, this is driving me up a wall. Ok, first off I would like to say hi to everyone as this is my first post! Now that we have been introduced, here is my problem. I am trying to create a billing system in which you generate invoices. The way I am going about this is using a table with rows for each item the user is placing on the invoice. I have a script that adds new rows to the table when the user wants to place more than one item on the invoice, thats all fine and dandy. The problem is that I also want to be able to delete any row of the table at any time so that the user can remove items as well. When the user presses the attached "delete" button on the row they wish to remove the delete script gets the table length and changes the id and name of every item in the rows below the one being deleted so that when I submit the data as a form it will have a predictable pattern for getting the post variables. At the moment the script runs fine the first time and does exactly what it is supposed to. The issue is that the second time you run it after it has changed the id and name values for the delete button elements on the lower rows it only makes it to the first alert() call! I have been pulling my hair out for days!!!!! Here is the Code: Code: function getEl(element) { var object = null; if (document.layers) { object = document.layers[element]; } else if (document.all) { object = document.all[element]; } else if (document.getElementById) { object = document.getElementById(element); } return object; } function addRow() { var tbl = getEl('invTbl'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); var cellqty = row.insertCell(0); var qty = document.createElement("<input type='text' name='qty_"+iteration+"' id='qty_"+iteration+"' size='4' value='1' onChange='javascript:updatePrice();' />"); cellqty.appendChild(qty); var cellitm = row.insertCell(1); var itm = document.createElement('input'); itm.type = 'text'; itm.name = 'itm_' + iteration; itm.id = 'itm_' + iteration; itm.size = 30; cellitm.appendChild(itm); var celldsc = row.insertCell(2); var dsc = document.createElement('input'); dsc.type = 'text'; dsc.name = 'dsc_' + iteration; dsc.id = 'dsc_' + iteration; dsc.size = 50; dsc.value = iteration; celldsc.appendChild(dsc); var cellprc = row.insertCell(3); var prc = document.createElement("<input type='text' name='prc_"+iteration+"' id='prc_"+iteration+"' size='9' value='1.00' onChange='javascript:updatePrice();' />"); cellprc.appendChild(prc); var celldel = row.insertCell(4); var del = document.createElement("<input type='button' name='"+iteration+"' id='"+iteration+"' value='Delete' onClick='javascript:removeRow(this.id);' />"); celldel.appendChild(del); } function removeRow(row) { alert("you are deleting row " + parseInt(row)); tbl = getEl('invTbl'); rowTotal = tbl.rows.length; alert("there are " + rowTotal + " rows!"); tbl.deleteRow(parseInt(row)); for ( i = 1; i < rowTotal; i++ ) { if ( i > parseInt(row) ) { place = i - 1; alert(i + " becomes " + place); qtycontainer = "qty_" + i; itmcontainer = "itm_" + i; dsccontainer = "dsc_" + i; prccontainer = "prc_" + i; delcontainer = i.toString(); buttonchange = place.toString(); getEl(qtycontainer).name = 'qty_' + place; getEl(qtycontainer).id = 'qty_' + place; getEl(itmcontainer).name = 'itm_' + place; getEl(itmcontainer).id = 'itm_' + place; getEl(dsccontainer).name = 'dsc_' + place; getEl(dsccontainer).id = 'dsc_' + place; getEl('dsc_'+place).value = getEl('dsc_'+place).id; getEl(prccontainer).name = 'prc_' + place; getEl(prccontainer).id = 'prc_' + place; getEl(delcontainer).name = buttonchange; getEl(delcontainer).id = buttonchange; alert("del button changed to " + getEl(i).id); } } // updatePrice(); } The button element for each row calls javascript:removeRow(this.id); Please help me figure out what I am doing wrong! The onChange is not calling my subroutine. I haven't played with JS in a few years, I'm sure this is stupidly simple. Any help is appreciated (or simpler way to do it!) Page is http://tinyurl.com/23l4k6w Here's the relevant code: Code: <form name="jump2"> <select name="comps"> <option value="0" selected># of Computers</option> <option value="1">1 Computer</option> <option value="2">2 Computers</option> <option value="3">3 Computers</option> <option value="5">5 Computers</option> <option value="10">10 Computers</option> </select> <select name="years" onchange="jump();"> <option value="0" selected>Years of Protection</option> <option value="1">1 Year</option> <option value="2">2 Years</option> </select> </form> <iframe name="buy_frame" src="" width="992" height="500" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe> <script language="javascript"> <!-- function jump() { if (jump2.comps.options[selectedIndex].value == 1) { if (jump2.years.options[selectedIndex].value == 1) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300318987]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } if (jump2.years.options[selectedIndex].value == 2) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199167]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } } if (jump2.comps.options[selectedIndex].value == 2) { if (jump2.years.options[selectedIndex].value == 1) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199158]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } if (jump2.years.options[selectedIndex].value == 2) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199168]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } } if (jump2.comps.options[selectedIndex].value == 3) { if (jump2.years.options[selectedIndex].value == 1) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199159]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } if (jump2.years.options[selectedIndex].value == 2) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199169]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } } if (jump2.comps.options[selectedIndex].value == 5) { if (jump2.years.options[selectedIndex].value == 1) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199160]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } if (jump2.years.options[selectedIndex].value == 2) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199170]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } } if (jump2.comps.options[selectedIndex].value == 10) { if (jump2.years.options[selectedIndex].value == 1) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199161]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } if (jump2.years.options[selectedIndex].value == 2) { window.open('https://secure.element5.com/esales/checkout.html?PRODUCT[300199171]=1&languageid=1&backlink=http%3A%2F%2Fwww.smartboxllc.com&cookies=1&nolselection=1&noquickbuy=1&showcart=1&affiliateid=200079763','buy_frame'); } } if (jump2.comps.options[selectedIndex].value == 0) { alert("You must select # of computers."); } else { alert("else");} //--> </script> Hi All, In my work here there is an application that has recently had a plugin coded up for it, the plugin allows custom message boxes to be opened up by the user when they roll on the help icons. The boxes open automatically and then close as soon as the mouse focus rolls off their box area. The boxes support java script content and html etc so can be very customised. I have coded a user form with various data capture fields. I would like the data in the fields to be reloaded if the user accidentally rolls off the box (as this will close it and the behavious cannot be changed :-<) I have used cookies and tested in browser and all the retreival and storage of the cookie data works fine. Problem is with this plugin app is that i cannot fit in the call to 'onload CheckForCookies()' anywhere - The boxes do not seem to appear as 'window opening events' so could anybody suggest a way of Adding the call to checkforcookies() into my form loading - that does not depend on a window opening event? There are four or five fields and i would like them all to update with whatever was last in them when the messagebox opens - it is not an api/ browser generated messge box, rather it is a custom web widget of some sort and i do not have access to the source code at this time. It is equally important to be able to create or refresh the cookie data for the fields when the user rolls off the box so they do not lose whatever info was typed in so far so i need to call like 'onunload SetAllCookies' Like i say i have the code to do the work, the problem is the functions are not being called as the behaviour of the little boxes does not trigger them as load / unload eventrs. I tested using 'onfocus' and this works but is nbo good as the user would only see the data they had 'lost' when they click on a field. alright, if my TR looks like this... Code: <tr class="colorRow('0',' ');" onmouseover="colorRow('0', 'over');" onmouseout="colorRow('0', 'out');"> <tr class="colorRow('1',' ');" onmouseover="colorRow('1', 'over');" onmouseout="colorRow('1', 'out');"> <tr class="colorRow(' ',' ');" onmouseover="colorRow(' ', 'over');" onmouseout="colorRow(' ', 'out');"> Why does this function not work? Code: function colorRow(serverID, when) { if(when == ' ') { if(serverID == ' ') { className = 'noBG'; } if(serverID == '1') { className = 'rowOdd'; } if(serverID == '0') { className = 'rowEven'; } } if(when == 'over') { className = 'rowOver'; } if(when == 'out') { if(serverID == '0') { className = 'rowEven'; } if(serverID == '1') { className = 'rowOdd'; } } } Hi all, here are two pieces of javascript code, I'm trying to make them both do the same thing but I really need some help. The first code works and the second does not. Here I predefine the variable, then I give it a place to be displayed. ---- var x=(Math.floor(Math.random()*5)); document.getElementById("information").innerHTML=x; //works ---- The next code is the same thing but in reverse. Here I predefine where to displayed the variable, then I give it the variable. ---- var x=document.getElementById("information").innerHTML; x=(Math.floor(Math.random()*5)); //not working ---- Is there any way that I could get this second code to work? I realise that x is being fulled with the inner HTML of "information" and then begin replaced with the random number. I don't know how to store x with a command and not simply the result of a command. I have tryed... x="document.getElementById(\"information\").innerHTML"; ...but then it's just a string. The last line replaces what ever is being stored in x. I don't know how to tell java script that this variable is for showing where the information is going, not just another place to store that information. I was thinking it would look something like... (x)=(Math.floor(Math.random()*5)); ...because it's the contact of x that I'm interested in and not x itself. I'm a bit lost here, any help would be appreciated. Thanks for your time. Would someone look at the code in my program at http://www.ckdoublenecks.com/prorent.html . I need to make the "amt paid" column an input field and then make changes to other fields if the "amt paid" field is Not " " (?). Thanks in advance.
I am looking for a script that would prevent an image from being highlighted by dragging the mouse. Thank you.
I'm trying to write a function that is similar to the ctrl+f functionality you get in IE, where you have a search string and when you click 'next' the whole string if matched is highlighted by the cursor. This works fine for inputs and text areas using the following code: Code: function setCaretPos(obj, start, end) { var range = obj.createTextRange(); range.moveStart('character', start); range.moveEnd('character', end - obj.value.length); range.select(); } But now I need to get it to work for normal text in a text node that is in the HTML/DOM. Is there an equivalent way of making the above method work for text in text nodes? Alternatively is there a way to make the browser (IE) at least focus on some text in a text node? (I could then highlight it with CSS styles). I'm trying to implement a syntax highlighter in my program, but jQuery 1.2.6 is giving me problems. This line specifically: Code: parse: [/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, new RegExp("^([:.#]*)(" + chars + "+)")], it messes with every javascript editor's syntax highlighting I've tried so far too. It looks like they're declaring a regex pattern without a delimiter. Can anybody make sense of this line? Hello everyone. This a css code in <head>: Code: .pagination{ width: 530px; /*Width of pagination DIV. Total width should equal slider's outer width (400+10+10=420)*/ text-align: right; background-color: white; padding: 5px 10px; } .pagination a{ padding: 0px 5px; text-decoration: none; color: #410B38; font-weight:bold; font-family:Arial; background: white; } .pagination a:hover, .pagination a.selected{ color: white; text-decoration: none; font-weight:bold; font-family:Arial; background-color: #410B38; } for a div with class=pagination (below) which contains the pagination of mysql data display: Code: <div class="pagination"> <?php $sql = "SELECT COUNT(id) FROM tablename"; $rs_result = mysql_query($sql,$mysql_connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 5); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='mysqldatadisplay.php?page=".$i."'>".$i."</a>"; }; ?> </div> I want everytime someone clicks on another number in order to change page, that clicked number to have different style than the other numbers as long as one stays on that page and when one clicks on a different number I want that number to behave in the same way. Someting like highlighting the navigational item that you're on. Thank you very much in advance! Alright, I'm using a Rooh.It WordPress plugin right now, but I don't like the way they do it, so I want to write my own code to do something similar. I want the user to be able to select the text they want to highlight, and the background color of that text changes to whatever color they have selected. How can I do this in JavaScript? I've spent some time trying to find a decent syntax highlighting javascript that will work in Firefox/Chrome and will work on <textarea> or at least act like a <textarea>. Bespin was working really well until I found out that I can only have 1 bespin div per page unless I use iframes (which wont work with my project) Codepress was really flakey and would sometimes show up as readonly in chrome. Syntax Highlighter doesn't say that it will work with a textarea (and I couldnt get it too) codeMirror also uses iframes. Anyone have some good suggestions? I've implemented the Google CSE on my website and it works fine but I'd like to ask if there is a way to highlight the searched words on destination sites using javascript? i.e.: 1. I type into the search form the word I need to find on my website --> 2. I get result site with links to subsites --> 3. After clicking one of the listed links I go back to my website, to certain subsite --> 4. The word I've been searching for is highlighted so I can easily find it. Thanks in advance. Alright so for my website (I've totally revamped it and what not) I want to make a code highlighter for source code / tutorials I've posted. At the moment I'm just using some css: Code: div.code { font:1em "Courier New"; margin: 10px auto 10px auto; background-color: #FFFFFF; border: thick solid #555555; color: #000000; white-space: pre; font-size: 12; } So the code stays neat and in a box. But what I want to do now is somehow make a small javascript function that scans the text inside the html file etc : Code: <div class="code">float TimerTicksPerSecond = 0; float TimerTicksPerMillisecond = 0; int value = 0; std::string s = "hello world"; </div> and can format it so float and int is blue, "hello world" is red etc. Be a great help if someone can point me in the right direction. As from the javascript I've done myself I can't see it being to hard. I'm just unsure how to scan for text inside like I have above. Cheers Myth. Hey, I have a jQuery script running on my site that makes it so when you click on a thumbnail, a different overflow:hidden div is scrolled to the anchor point that thumbnail was linking to. I want to make it so the thumbnail that you clicked becomes selected (and all over thumbnails become unselected). This could be with a border, a shadow, an image appearing behind it, opacity - basically anything (preferably an image appearing behind it). I'm pretty much a javascript noob, but common sense tells me that this isn't possibly with basic CSS. How do I go about doing this? PS, if you want a clearer picture of what I'm referring to on my site, check http://bit.ly/83ftPF Thanks a ton for your time, I really appreciate it! -Joel Hello there, I'm a 30yr old returning to school and I signed up for a CMIS102 class, thinking it be more explanatory as the syllabus let on. But I was wrong. While I do understand some of what the professor has been teaching us, like modular programming and IfElse statements, I can't wrap my head around things like While Loops. My professor has saddled us with a couple assignments, requiring us to write in pseudocode and I was wondering if anyone could explain what he wants from this assignment or even help me with it, that maybe I can finally have a grasp of it, and will know what I'm doing on the final. ~Tia P.S. I've posted the assignment question below: I need to write a pseudo-codepseudocode for the following question but don't know how: Write a program to read a list of exam scores (in the range 0 to 100) and to output the total number of grades and the number of grades in each letter=grade category. The end input is indicated by a negative score as a sentinel value. (The negative value is used only to end the loop, so do not use it in the calculations. Example: 88 93 55 77 100 -1 (The output would be) Total number of grades = 5 Number of A's =2 Number of B's = 1 Number of C's =1 Number of D's = 0 Number of F's =1 Must prompt user to run again I am new to JavaScript and looking for its specification so I can learn from the manual. I see its made by Netscape, which is now liquidated... and cannot find a consortium for it.. so, am I correct in guessing its now a lost tribe?
|