JavaScript - Currency Text Is Changed Based On Url
Anyone ever did this before?
domain1.com will have a paragraph of one currency price domain2.com will have the same paragraph with a different currency price. Similar TutorialsHello, Firstly - relatively new to javascript. I have seen many examples of code that will return a passed value in a currency format - however I have a sales form that is calculating values via a function in the text boxes I want formatted with a currency ($) symbol. The function that is called is not passing any values, and returning a calculation of the form subtotals per item, and then total sales figure. Can anybody give me any hints on format these cells to a currency value? I can give examples of how my code is currently if required. Thanks in advance Hi, I'm hoping this will be an easy one for you experts out there. I am working on a convention registration form. What I'm trying to do is have the text "50.00" pop into the COST field when any text (even if it's only one character) is entered into the NAME field. If the text in the NAME field is deleted, the "50.00" should also be deleted. Does anyone have a script that does this? Thanks! I want to insert text to a textarea based on the selected text. It should insert tags like the buttons for posting on this form work. Ie: If 'bar' is selected, and I click 'b', then I get: Code: Foo bar frog becomes: Code: Foo <b>bar</b> frog I found some code that works for firefox, but I need it to work in explorer as well. Do you have any ideas or examples how to do this? Here's the code I'm currently using. ( Works right in ff3. In IE7 it appends the tags at the end of the text. I want it to insert based on my selection. ) Usage: Code: <a onclick="insertTags('<b>', '</b>', document.forms.formpost.text);return false;" href="javascript:void(0);">[ Bold ]</a> insert function: Code: <script type="text/javascript"> // Surrounds the selected text with text1 and text2. function insertTags(text1, text2, textarea) { // Can a text range be created? if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange) { var caretPos = textarea.caretPos, temp_length = caretPos.text.length; caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2; if (temp_length == 0) { caretPos.moveStart("character", -text2.length); caretPos.moveEnd("character", -text2.length); caretPos.select(); } else textarea.focus(caretPos); } // Mozilla text range wrap. else if (typeof(textarea.selectionStart) != "undefined") { var begin = textarea.value.substr(0, textarea.selectionStart); var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart); var end = textarea.value.substr(textarea.selectionEnd); var newCursorPos = textarea.selectionStart; var scrollPos = textarea.scrollTop; textarea.value = begin + text1 + selection + text2 + end; if (textarea.setSelectionRange) { if (selection.length == 0) textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length); else textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length); textarea.focus(); } textarea.scrollTop = scrollPos; } // Just put them on the end, then. else { textarea.value += text1 + text2; textarea.focus(textarea.value.length - 1); } } </script> Curious about the following issue. I currently have a dynamic drop-down based on the value of each option.. If selection in top drop-down is B it will show all options with a B contained in the second/resulting drop-down. Now - I also want to evaluate the options by having the script check for a few keywords.. Example - have it evaluate the drop-down on page load for options with text containing 'blah123' (ex. <option value="0323G">Qwerty - blah123</option>). And if any of the options have that text the script will generate an additional drop-down menu allowing you to select blah123 or other specified text. Say another thing I'd like to search each text string for is 'abump'. If there is 'blah123' and 'abump' contained within the drop-down, a third drop-down menu will be generated (as said before) with only blah123 and abump as options. Whichever of these is selected will narrow down the options available in the final drop-down menu. If any clarification is needed I would be more than happy to make this more clear. Any ideas? Hi Guys, I am looking for a script to change text on a page based on the time of day. From 9am - 5pm weekdays I would like the page to display 'Open', and outside of that window to display 'Closed'. I am using HTML & PHP. Any help would be greatly appreciated. Thanks, Matt I am looking for a bit of Javascript that can hide a sentence in my website if the URL contains certain words, most specifically INFO or CERT. Any idea how I can do this? Your help is appreciated. Thank You, Kevin Brown I'm taking a beginning javascript class and have been trying to figure out one last part of a homework assignment and am just not seeing how to work it out. Any help is greatly appreciated! What I'm having trouble with is doing the text verification. When a user selects an option from the select list they then need to type in the text area given. If the user doesn't type the word selected in the list then an error message should appear under the text area. If you look at my code you'll see that I have the text_check() function doing the verification. I can get it to work when there is only one option but once I add the other two it stops working. I've tried if... else and other variations, but can't seem to nail it down. Thanks! Code: function select_function() { var medical=document.getElementById("medical_list") var selected_item=medical.selectedIndex if (selected_item==0) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Medication" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } if (selected_item==1) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Hospitalization" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } if (selected_item==2) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Physician" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } } function text_check() { var user_comments=document.getElementById("comments").value.toLowerCase(); var med_comment=user_comments.indexOf('medication'); var hosp_comment=user_comments.indexOf('hospitalization'); var phys_comment=user_comments.indexOf('physician'); mySelectList = document.getElementById("medical_list"); if (mySelectList.value='Medication' && med_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Medication"+"</span>"+" somewhere in the text"; } if (mySelectList.value='Hospitalization' && hosp_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Hospitalization"+"</span>"+" somewhere in the text"; } if (mySelectList.value= 'Physician' && phys_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Physician"+"</span>"+" somewhere in the text"; } } function submit_alert() { alert("You submitted the form") } function clear_error() { document.getElementById("word_error").innerHTML=""; } function changeDR() { var my_textarea=document.getElementById("comments"); var comment_string=my_textarea.value; var doctor=comment_string.indexOf('Dr.'); var comment_string2=''; if (comment_string < 0) { comment_string2=comment_string } else { comment_string2=comment_string.replace('Dr.','Doctor') } my_textarea.value=comment_string2; } </script> </head> <body style="background-color: silver"> <h2>Medical History</h2> Select Category: <br> <select id="medical_list" onChange="select_function();"> <option>Medication</option> <option>Hospitalization</option> <option>Physician</option> </select> <br><br><br> <div id="enter_info">Enter Your <font color="blue">Medication</font> Information:</div> <br> <form method="post" action=""> <textarea id="comments" cols="60" rows="15" onBlur="text_check();" onFocus="clear_error();" onkeyup="changeDR();"> </textarea><br> <div id="word_error"></div><br> <input type="submit" value="Submit Information" onClick="submit_alert();"/> </form> </body> </html> Hello I am trying to do something similar to this post http://www.codingforums.com/showthread.php?t=168903 except I need it to be dependent on the hour and minute. Background: I am trying to create a schedule website, the schedule has say 20 items and I want it to display the current "active" event in the schedule, 1 previous event and 3 future events so a total of 5 items from the schedule. An event can range from 30 minutes to 2 hours long, so simply using the above code will not work. It needs to take the minutes into consideration as well. Let me know if you have additional questions. EDIT: 17-Mar-12 @ 12:37PM I would rather not use a bunch of if statements. (http://www.codingforums.com/showthread.php?t=250358) The schedule could change mid day so having to go through and edit a bunch of if statements would not be ideal Hello, I'm looking for help as I have the jCarouselLite feature functioning on my website and am looking for a way of displaying another image to the right of the carousel, dependent upon which image is visible in the carousel. I toyed with the idea of implementing another snippet of JavaScript to swap the text to the right and manually synching the swap time wise, but quickly abandoned this idea for a number of reasons, particularly as the carousely has buttons to scroll through the images displaying. I have to admit I'm not particularly great with JavaScript, but was thinking along the lines of another function that listens for the image that is displayed, but have no idea if am way off the mark, or even if this is the right track - no idea how to implement. Any help would be very gratefully recieved. Thanks, Matt Hello! I need some help here. I need to pre-populate a name and a phone number box based on what's entered in the employee id box. By entering in the employee id - EMPLOYEE ID: [JOHN R] It automatically fills in - Employee Name: [John Roberts] Employee Phone: [1234567890] Thanks. I have a form that has a pretty complicated combo box - a user starts typing text, it queries a database for matches, and displays the results to the user. The user can then select the match they desire and it has a value id, which I am currently sending to a hidden field in the form. So, for example: user starts typing in a movie name, Seven - it returns Seven and user selects it. The form submits the id of the movie seven (say 12) to a hidden field. Where I am stumped: Once a user selects a movie title, I have another drop down select box that is to display the available formats of the movie by querying my database based on the product id (12) and returning the available formats in the list: DVD BLUERAY VHS I am pretty good at programming, but I cannot figure this out - how to make the select box fire and return results once the value for the textbox has been captured. Can anyone help me? Is there a way to call javascript functions based on the text between a span element? In other words if I have <span id="mySpan">Bronze</span> then it will call a javascript function but if I have <span id="mySpan">Silver</span> then it will call a different function? Thanks! I have a web page created using plsql web toolkit. I want to set the text box values for street line 2 and zip based on user selection in select drop down which is street line 1. The select drop down list is based on a cursor selecting data from the Oracle database. I'm not sure if I need to use an array in the javascript code or if I can set the values some where in my package. Any advice would be appreciated. cursor: Quote: cursor bldglistc is select stvbldg_code, stvbldg_desc, slbbldg_street_line1, slbbldg_city, slbbldg_stat_code, slbbldg_zip from stvbldg, slbbldg where stvbldg_code = slbbldg_bldg_code (+) and stvbldg_desc not like 'DNU%' and stvbldg_desc not like 'Online%' order by slbbldg_bldg_code; bldg_record bldglistc%ROWTYPE; Javascript in package: Quote: htp.p(' <SCRIPT LANGUAGE="JavaScript" TYPE = "text/javascript"> function UpdateNextField(which1,which2,fld1,fld2) { document.getElementById(fld1).value = which1.value; document.getElementById(fld2).value = which2.value; } </SCRIPT> '); Form code from package: Quote: HTP.formopen ('bwgkogad.P_ProcAddrUpdate', 'post'); twbkfrmt.P_FormHidden ('atyp', atyp); twbkfrmt.P_FormHidden ('seqno', seqno); twbkfrmt.p_tableopen ( 'DATAENTRY', cattributes =>G$_NLS.Get('BWGKOAD1-0003','SQL','SUMMARY="This table shows Address Selected for Update."') ); twbkfrmt.p_tablerowopen; twbkfrmt.p_tabledataheader (stvatyp_rec.stvatyp_desc, ccolspan => '5'); twbkfrmt.p_tablerowclose; twbkfrmt.p_tablerowopen; twbkfrmt.p_tabledatalabel ( twbkfrmt.f_formlabel ( g$_nls.get ('BWGKOAD1-0007', 'SQL', 'Address Line 1:'), idname => 'street_line1_input_id' ) ); twbkfrmt.p_tabledataopen (ccolspan => '5'); HTP.formselectopen ( 'str1', '', 1, cattributes => 'ID="street_line1_input_id" onChange="javascript: UpdateNextField(this,this,''street_line2_input_id' ',''zip_input_id'')"' ); OPEN bldglistc; LOOP FETCH bldglistc INTO bldg_record; IF bldglistc%NOTFOUND THEN EXIT; END IF; IF address_rec.spraddr_street_line1 = bldg_record.slbbldg_street_line1 THEN twbkwbis.p_formselectoption ( bldg_record.slbbldg_street_line1, bldg_record.slbbldg_street_line1, 'selected' ); ELSE twbkwbis.p_formselectoption ( bldg_record.slbbldg_street_line1, bldg_record.slbbldg_street_line1 ); END IF; END LOOP; CLOSE bldglistc; HTP.formselectclose; twbkfrmt.p_tabledataclose; twbkfrmt.p_tablerowclose; twbkfrmt.p_tablerowopen; twbkfrmt.p_tabledatalabel ( twbkfrmt.f_formlabel ( g$_nls.get ('BWGKOAD1-0008', 'SQL', 'Address Line 2:'), idname => 'street_line2_input_id' ) ); twbkfrmt.p_tabledata ( twbkfrmt.f_formtext ( 'str2', 70, 75, address_rec.spraddr_street_line2, cattributes => 'ID="street_line2_input_id" readonly' ), ccolspan => '5' ); twbkfrmt.p_tablerowclose; twbkfrmt.p_tablerowopen; twbkfrmt.p_tabledatalabel ( twbkfrmt.f_formlabel ( g$_nls.get ('BWGKOAD1-0013', 'SQL', 'ZIP or Postal Code:'), idname => 'zip_input_id' ) ); twbkfrmt.p_tabledata ( twbkfrmt.f_formtext ( 'zip', NULL, 30, address_rec.spraddr_zip, cattributes => 'ID="zip_input_id" readonly' ), ccolspan => '5' ); twbkfrmt.p_tablerowclose; twbkfrmt.p_tableclose; HTP.para; -- HTP.formsubmit (NULL, G$_NLS.Get('BWGKOAD1-0054','SQL','Submit')); HTP.formreset (g$_nls.get ('BWGKOAD1-0055', 'SQL', 'Reset')); HTP.formclose; Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks Hello I have this script Code: /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Created by: Mario Costa | */ function currencyFormat(fld, milSep, decSep, e) { var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; if (whichCode == 13) return true; // Enter if (whichCode == 8) return true; // Delete key = String.fromCharCode(whichCode); // Get key value from key code if (strCheck.indexOf(key) == -1) return false; // Not a valid key len = fld.value.length; for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; aux = ''; for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); aux += key; len = aux.length; if (len == 0) fld.value = ''; if (len == 1) fld.value = '0'+ decSep + '0' + aux; if (len == 2) fld.value = '0'+ decSep + aux; if (len > 2) { aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--) { if (j == 3) { aux2 += milSep; j = 0; } aux2 += aux.charAt(i); j++; } fld.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) fld.value += aux2.charAt(i); fld.value += decSep + aux.substr(len - 2, len); } return false; } and I call it like that: onKeyPress="return(currencyFormat(this,',',',',event))" the ouput is: 100,000.00 How can I get rid of of the last 2 ziros after the last dot I need this kind of output 1,000 10,000 100,000 1,000,000 any help ? I changed the code and it didn't work, so I tried to put it back to what it was. Now, the whole thing isn't working. I am a lost little child. Can someone help me please. http://www.boothemusic.com/ Here is the code: Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head xmlns=""> <title>Boothe Brothers Music</title> <script type="text/javascript"> function loadContent(page) { switch(page) { case "home": document.getElementById("middle").src = "http://boothemusic.com/middle.html"; break; case "store": document.getElementById("middle").src = "http://boothemusic.com/catalog"; break; case "Electric Guitars": document.getElementById("middle").src = "http://boothemusic.com/catalog/index.php?main_page=index&cPath=1&zenid=9feb6660698a06a51571cc4cef1c3e60"; I left out most of the code because I only edited the line "case "store".....". Help, i need to edit my code to submit the form so that it will submit the data once clicked on. I am using this tutorial he http://www.switchonthecode.com/tutor...-jquery-plugin here is my code so far: my JS file: // run rating jQuery.fn.ratings = function(stars, initialRating) { //Save the jQuery object for later use. var elements = this; //Go through each object in the selector and create a ratings control. return this.each(function() { //Make sure intialRating is set. if(!initialRating) initialRating = 0; //Save the current element for later use. var containerElement = this; //grab the jQuery object for the current container div var container = jQuery(this); //Create an array of stars so they can be referenced again. var starsCollection = Array(); //Save the initial rating. containerElement.rating = initialRating; //Set the container div's overflow to auto. This ensure it will grow to //hold all of its children. container.css('overflow', 'auto'); //create each star for(var starIdx = 0; starIdx < stars; starIdx++) { //Create a div to hold the star. var starElement = document.createElement('div'); //Get a jQuery object for this star. var star = jQuery(starElement); //Store the rating that represents this star. starElement.rating = starIdx + 1; //Add the style. star.addClass('jquery-ratings-star'); //Add the full css class if the star is beneath the initial rating. if(starIdx < initialRating) { star.addClass('jquery-ratings-full'); } //add the star to the container container.append(star); starsCollection.push(star); //hook up the click event star.click(function() { //set the containers rating containerElement.rating = this.rating; // document.voteform.submit(); //When clicked, fire the 'ratingchanged' event handler. //Pass the rating through as the data argument. elements.triggerHandler("ratingchanged", {rating: this.rating}); }); star.mouseenter(function() { //Highlight selected stars. for(var index = 0; index < this.rating; index++) { starsCollection[index].addClass('jquery-ratings-full'); } //Unhighlight unselected stars. for(var index = this.rating; index < stars; index++) { starsCollection[index].removeClass('jquery-ratings-full'); } }); container.mouseleave(function() { //Highlight selected stars. for(var index = 0; index < containerElement.rating; index++) { starsCollection[index].addClass('jquery-ratings-full'); } //Unhighlight unselected stars. for(var index = containerElement.rating; index < stars ; index++) { starsCollection[index].removeClass('jquery-ratings-full'); } }); } }); }; $(document).ready(function() { $('#example-1').ratings(10).bind('ratingchanged', function(event, data) { $('#example-rating-1').text(data.rating); }); }); My html: PHP Code: echo '<form action="stream.php?task=vote" name="voteform" method="post"> '; echo ' <div id="example-1"></div> <input id="example-rating-1" type="hidden" name="score" value="0"/>'; echo '</form>'; Heres what i want it to do, I want it to submit the form once a star has been clicked, i already achieved this with the document.voteform.submit() in comments in the JS file but i cant seem to get the input to change so that it submits the actual user vote value. Please help me Hi I have the following currency converter code which works fine, but I need to make it possible for someone else to edit the euro price using a visual editor such as contribute. 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script language='javascript'> exchRate = 1.13; function getUKP(price) { document.write('(£' + Math.round(price / exchRate) + ')'); } </script> </head> <body> <strong>€526</strong> <script type="text/javascript">getUKP('526');</script><br /><br /> <strong>€1999</strong> <script type="text/javascript">getUKP('1999');</script> </body> </html> This code requires someone to change the figure in the javascript as well as the html. I guess I need to somehow automatically pick up the numeric characters only from the html which appear on the same line of code... or perhaps there's an easier way.? Any help would be much appreciated. Thanks Hello everyone! I'm currently doing an assignment which involves a snack machine. I'm currently working on the PacketOfCrisp class. It needs to start with 10 crisps, and have a boolean field for whether or not it's closed. This field is called open and is obviously set to false when the object is created. It also needs to give out some messages, ie if the packet is not open then a message should appear saying that the packet is closed. If the pack has no crisps left a message should appear saying as such. Other than that when selecting eatCrisp the amount of crisps in the packet should go down by one. Here is what I have so far: Code: public void eatCrisp() { if(open = false) { System.out.println("Open packet"); } else if (open = true && numOfCrisps >= 1) { numOfCrisps = numOfCrisps - 1; } else { System.out.println("No Crisps!"); } } Now for some reason when I invoke eatCrisp it takes out a crisp and changes the "open" field of the object to true and I can't figure out why. As far as I can figure it should be giving me a message of "Open packet" until I open the packet with the "openPacket" method, but instead "eatCrisp" is doing that by itself. Any ideas? |