JavaScript - Using Javascript To Modify A Hyperlink.
Edit: Problem solved.
Similar TutorialsI'm trying to create a form where the user enters data in a field and is redirected to a URL based on that entry - example: user enters 1234 and he is directed to mypage.com/1234/index.htm - if that folder does not exist it would give a 'try again' error. Any help would be greatly appreciated Thanks in advance Cyber-guys Hi, I came across this thread and I've decided to use jmrker's code. Code: <html> <head> <title>Clock Example</title> <script type="text/javascript"> function startTime() { var d=(new Date); var str = d.toLocaleTimeString().toLowerCase().replace(' ',''); var tmp = d.toLocaleDateString().split(' '); var dm = d.getDate(); switch (dm) { case 1: case 21: case 31: dm += 'st'; break; case 2: case 22: dm += 'nd'; break; case 3: case 23: dm += 'rd'; break; default: dm += 'th'; break; } str += ' '+tmp[0].substr(0,3)+', '+tmp[1].substr(0,3)+' '+dm+', '+tmp[3]; startTime.out.innerHTML = str; } onload = function(){ startTime.out=document.getElementById("time"); setInterval(startTime, 1000); }; </script> <body> <div id="time"></div> </body> </html> However, I would like to modify some elements. Right now the date and time are displayed in this format: Quote: 9:58:45am Sat, Feb 26th, 2011 I would like to know how to change it to look like this: Quote: SAT 09:58:45 AM (for example) Could someone please break down the code and let me know what I need to change to get this to work? Or, if it's less trouble, just change the code for me? Thanks, I appreciate your time. I have a page that open two frames. Second frame, most of the page, is empty. First frame contains a form that retrieves user input, when you click the button, it send that input back to the original parent html, which detects the GET parameters, and builds a custom URL. I want to then load that custom URL in the 2nd empty frame. I figure I need to modify the src atttribute of the 2nd frame in the frameset, but I can't make it work. Code: <frameset id='parent' rows='10%,90%'> <frame id='frm1' src='./form.html' /> <frame id='frm2' src='' /> </frameset> <script>modFrmSrc();</script> where modFrmSrc() checks for the GET values, builds the URL, and then tries to load the URL in frm2. Is there a way to get this done? I need educating please. I have a javscript page (fred.js) that contains some variables and some code. I want to be able to change the variables (in particular an array) within fred.js on the server and store the new version of fred.js back on the server. I can write a php routine that stores the array in a MySQL table. Now I want to know how to write some code (and in what language) to read the MySQL table and update fred.js and store it back onto the Server. Can someone please tell me what language I should be using to do this (Ajax??) so that I can do some reading please. I could of course simply write some php code to read the table and pass the parameters to a js page and build the array as each person accesses the web page but this would be slow. Hence I would prefer to have the ability to update the js page and store it back onto the server. Hi all.... newbie here. Have just finished my eccomerce site and it's ready to go but have come across a stumbling block. I use webplus4 which is a great web design program... except for one thing. The site search tool is very weak... it won't find results for words of less than 4 characters... and since my website is about plush pets this is important. For instance if you type in the breed 'pug' it says 0 results found. Same if you enter Old English Sheepdog, it ignores the entire search term because of the world 'old'. If you enter plush pug, it also ignores the entire search string. I don't have the money to purchase software nor the time and then configure the javascript to match my site. Is there anyone out there that can modify the following javascript file (jsSiteSearch.js) so that the search will not ignore words of 3 letters? Am aware that once modified I will have to replace the file each time but it will be worth it. By the way, no one on the webplus forums seems to know how to do it. Here is the code... (have removed all the keywords)... function GetSiteSearchResults(newWindow,frameObject,frameObjectName,fontFace,fontSize,fontColour,linkFace,lin kSize,linkColour,resultsText) { var sTerms=""; var iDepth = 0; var sURL = new String(document.location); if (sURL.indexOf("?") > 0) { var arrParams = sURL.split("?"); var arrURLParams = arrParams[1].split("&"); for (var i=0;i<arrURLParams.length;i++) { var sParam = arrURLParams[i].split("="); var sValue = unescape(sParam[1]); if( sParam[0] == frameObjectName) sTerms = sValue; if( sParam[0] == "depth") iDepth = parseInt(sValue); } } var d=frameObject.document; if (sTerms=="") {d.open(); d.write("<html><head></head><body style=\"background: transparent;\"></body></html>"); d.close();return;} var sBack=""; for (i=0; i<iDepth; i++) sBack+='..\\\\'; d.open(); d.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); d.write("<html lang=\"en\">"); d.write("<head>"); d.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); d.write("</head>"); d.write("<body style=\"margin: 0px 0px 0px 0px; font-family: "+fontFace+"; font-size: "+fontSize+"; color: "+fontColour+"; background: transparent;\">"); d.write("<div id=\"wpSearchResults\"></div>"); d.write("<script type=\"text/javascript\">"); d.write("var wordMap = new Array(\"...........................................); d.write("function doNav(ind)"); d.write("{"); if (newWindow) d.write(" window.open(\""+sBack+"\"+linkMap[ind],\"_blank\");"); else d.write(" parent.window.location.href=linkMap[ind];"); d.write("}"); d.write("function wpDoSearch(searchTerms){"); d.write("var terms = searchTerms.split(\" \");"); d.write("if (terms==\"\") return;"); d.write("var results = \"\";"); d.write("var resultscount = 0;"); d.write("for (var i=0; i<wordMap.length; i++)"); d.write("{"); d.write(" var found=true;"); d.write(" for (var j=0; j<terms.length; j++)"); d.write(" if (wordMap[i].indexOf(terms[j].toLowerCase())==-1) found=false;"); d.write(" if (found)"); d.write(" {"); d.write(" results+=\"<a style=\\\"cursor: pointer; font-family: "+linkFace+"; font-size: "+linkSize+"; color: "+linkColour+"; \\\" onclick=\\\"doNav(\"+i+\");\\\"><u>\"+pageMap[i]+\"</u></a><br>\"+preMap[i]+\"...<br><br>\";"); d.write(" resultscount++;"); d.write(" }"); d.write("}"); d.write("document.getElementById(\"wpSearchResults\").innerHTML=resultscount+\" "+resultsText+" \"+searchTerms+\"<br><br>\"+results;"); d.write("}"); while(sTerms.indexOf("\"") != -1 ) { sTerms = sTerms.replace("\"",""); }; d.write("wpDoSearch(\""+sTerms+"\");"); d.write("</script>"); d.write("</body></html>"); d.close(); } Thanks so very much in advance. Any help asap will be much appreciated. Cheers Hello everyone, Here's the scenario I wish to plan out. I have an index.htm page ready. I want to be able to put in javascript code into the HTML coding that will write the ip address of the actual server that is hosting the website into a hidden text box. Then I want to insert this ip address into a hyperlink in the original index.htm to link to another html page (this will be a SSL secure page instead i.e. https://<ip address>). Also vice versa. (With SSL index.htm page have code that writes ip into hidden text box then hyperlink to the original http index page) thanks. Hope you follow me I've been hammering at this for quite a while and it has me stumped. I have 4 variables that I am creating in the head section of my code. I am passing 2 parameters to my test page via the url and they are intended to be used to construct alternate url's for use by menu buttons. This my test url. My test link Here is a code snippet that creates the alternate url's. Code: <script type="text/javascript"> var videofile = swfobject.getQueryParamValue('id'); var af = swfobject.getQueryParamValue('af'); function enLink() { var enLink = "http://jim.playourvideo.net/lsatest.htm?id=" + videofile + "&af=" + af; alert(enLink); } function spLink() { var spLink = "http://jim.playourvideo.net/lsatest.htm?id=sp" + videofile + "&af=" + af; alert(spLink); } function grLink() { var grLink = "http://jim.playourvideo.net/lsatest.htm?id=gr" + videofile + "&af=" + af; alert(grLink); } function frLink() { var frLink = "http://jim.playourvideo.net/lsatest.htm?id=fr" + videofile + "&af=" + af; alert(frLink); } </script> I am trying to call the appropriate function by clicking on one of menu buttons. When I click any of the buttons I get an alert showing that my url is properly constructed. But the link never seems to fire and result in switching video files. I did also try it with onclick - same result. What should happen is the page should reload and play a different regionally captioned file. For testing I haven't captioned the test files. Just trying to get the logic working. I'd sure appreciate some advice. Jonni I'm not that familiar with classic ASP or Javascript but need to change an exisiting program to do the following: Add a link to a page but only for certain marketers. I have a classic ASP page that has a couple of hyperlinks for each marketer that is selected from a combobox drop down. The new hyperlink is to be added but only for select marketers. The rest don't even get to see this new hyperlink. I added a function in Javascript as such: Code: function IsPikeESCO(UID,UCD) { var strTemp; var mktrno,mktname; var frm; var IsPike; IsPike = false; frm = document.Downloads; strTemp=frm.MKTRACCT.options[frm.MKTRACCT.selectedIndex].text; mktrno=strTemp.substring(0,10); switch (mktrno) { case 8: IsPike = True; break; case 99: IsPike = True; break; case 162: IsPike = True; break; } return IsPike; } Now I need to check if True then display the hyperlink, so I came up with this, which I know is not correct: Code: <tr><td></td><td <%IF <a HREF="javascript:IsPikeESCO('<%response.write request("passUID")%>','<%response.write request("passUCD")%>')" = True THEN%> onMouseOver="/orradata/pike.DAT">Pike Data</font></a> <%END IF%> I want to be able to check the fuction for each marketer and if return is TRUE, then produce the hyperlink which will open a data file if clicked. Can someone help? I'm not sure how to use the <%IF statement in conjunction with a javascript function that checks for a return value, and based on that return value, does some action. Hey all, I'm sure this is very basic but I'm having a hard time adding a hyperlink to text within javascript. I want to add a website link to the text 'click here' that is being displayed under the image within javascipt. I end up modifying the whole image instead, removing the javascript that displays the larger version of the image. Can anyone help me out please? Here's the coding. I'm using Dreamweaver CS5 on a PC to modify a few things and using another website building program to get the basic layout. I'm just a small business owner trying to get my website off the ground. Thanks in advance! <div id="imCel1_01"> <div id="imCel1_01_Cont"> <div id="imObj1_01"> <a href="javascript:imShowBox('files/june2011.jpg',500,500,'Right click to print....................Click HERE for website!','IMG','t');" title=""><img src="images/p025_1_01.jpg" alt="" title="" /></a> </div> Hi, I need to replace "Link Text" with the value in the variable (myNewString). myNewString is just text e.g hello code document.write(myNewString); <a href="welcome.html">Link text</a> i need some thing like the below or even a php version of it <a href="welcome.html">(myNewString)</a> THANKS!!!!!!!!! Hi. I have a bunch of textboxes that I need to run some JS on with onclick. However, no matter what I do, I cannot get it to work. I have this JS in an external file: Code: <script language="javascript" type="text/javascript"> function ClearDefault () { if (document.this.value==document.this.defaultValue) { document.this.value=''; document.this.style.color='black' } } </script> and am using onfocus="ClearDefault()" Help please. Thanks. :-) I need help making it possible for the prefixes to be available when the post is being Modify? The user have to go back and change their prefixes to ended after they get the result for the outcome of the buy, sell, trade. When I hit Modify the prefix box was no longer available. It is on the subject line when I hit modify: Example. I have a thread title "Testing" and I chose Buy prefix when I started the thread. When I hit Modify, the prefix box is no longer available but the subject does say Buy:Testing. I would have to go and delete the Buy from the subject and manually type Ended. And also each prefixes a specific color if that's possible (i.e., Buy , Sell , Trade , Ended ) The prefix box now is below the subject line. I would love for it to be next to the subject line like in this forum. THANKS! <script type='text/javascript'> /* Add prefixes to posts*/ var prefixes = ['Buy:','Sell:','Trade:','Ended:']; if( new RegExp('post$','i').test( this.location.href )) { document.postForm.nextaction.nextSibling.disabled = true; var Tab = document.postForm.subject.parentNode.parentNode.parentNode; var iRow = Tab.insertRow(2); var iCell; iCell = iRow.insertCell(0); iCell.className = 'windowbg'; var Font = document.createElement('font'); Font.size = 2; Font.appendChild( document.createTextNode('Prefixes:') ); iCell.appendChild( Font ); iCell = iRow.insertCell(1); iCell.className = 'windowbg'; var Select = document.createElement('select'); Select.id = 'preprepre'; Select.options[0] = new Option('Choose prefix'); for( var s = 0 ; s < prefixes.length ; s ++ ) Select.options[s+1] = new Option(prefixes[s]); iCell.appendChild( Select ); function checkpre(event) { if( document.getElementById('preprepre').selectedIndex == 0 ) document.postForm.nextaction.nextSibling.disabled = true; else document.postForm.nextaction.nextSibling.disabled = false; } function addpre(event) { document.postForm.subject.value = document.getElementById('preprepre').options[ document.getElementById('preprepre').selectedIndex ].innerHTML+document.postForm.subject.value; } if(document.addEventListener) { document.getElementById('preprepre').addEventListener('change',checkpre,false) document.postForm.addEventListener('submit',addpre,false); }else{ document.getElementById('preprepre').attachEvent('onchange',checkpre); document.postForm.attachEvent('onsubmit',addpre); } } </script> Hi need help with a loan calculator script, i know the moderator frowns on such requests but i just have to, im willing 2 buy a cup of coffee if it works, i want the code below to display the total loan repayment amount instead of the monthly payment payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months)) , eg if if l0an is 20$ payment is in 4 months, intrest rate is 15% display = amount to be repaid. thanks Code: <script language="JavaScript"> <!-- function showpay() { if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) || (document.calc.months.value == null || document.calc.months.value.length == 0) || (document.calc.rate.value == null || document.calc.rate.value.length == 0)) { document.calc.pay.value = "Incomplete data"; } else { var princ = document.calc.loan.value; var term = document.calc.months.value; var intr = document.calc.rate.value / 1200; document.calc.pay.value = princ * intr / (1 - (Math.pow(1/(1 + intr), term))); } // payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months)) } // --> </script> The results of this loan payment calculator are for comparison purposes only. They will be a close approximation of actual loan repayments if available at the terms entered, from a financial institution. This is being provided for you to plan your next loan application. To use, enter values for the Loan Amount, Number of Months for Loan, and the Interest Rate (e.g. 7.25), and click the Calculate button. Clicking the Reset button will clear entered values. <p> <center> <form name=calc method=POST> <table width=60% border=0> <tr><th bgcolor="#aaaaaa" width=50%><font color=blue>Description</font></th> <th bgcolor="#aaaaaa" width=50%><font color=blue>Data Entry</font></th></tr> <tr><td bgcolor="#eeeee">Loan Amount</td><td bgcolor="#aaeeaa" align=right><input type=text name=loan size=10></td></tr> <tr><td bgcolor="#eeeee">Loan Length in Months</td><td bgcolor="#aaeeaa" align=right><input type=text name=months size=10></td></tr> <tr><td bgcolor="#eeeee">Interest Rate</td><td bgcolor="#aaeeaa" align=right><input type=text name=rate size=10></td></tr> <tr><td bgcolor="#eeeee">Monthly Payment</td><td bgcolor="#eeaaaa" align=right><em>Calculated</em> <input type=text name=pay size=10></td></tr> <tr><td bgcolor="#aaeeaa"align=center><input type=button onClick='showpay()' value=Calculate></td><td bgcolor="#eeeeaa" align=center><input type=reset value=Reset></td></tr> </table> </form> <font size=1>Enter only numeric values (no commas), using decimal points where needed.<br> Non-numeric values will cause errors.</font> </center> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p> Hi I am a new user to JS, and I have a problem he I have some JS code to work on a data set with file name "data.txt" in the header section of an HTML page. Code: <script type="text/javascript" src="data.txt"></script> What I am trying to do is to ask a user to input a different file name, then update the file name in the <script> tag, for example, to Code: <script type="text/javascript" src="new_data.txt"></script> But I don't know how to update the file name. Any help will be appreciated. Can someone help me to modify this JS to close if user is no longer hovering over child link after 5 seconds? Code: $(document).ready(function () { $('#menuHolder ul li a').mouseover(function (event) { if (this == event.target) { $(this).parent().toggleClass('clicked'); if ($(this).parent().attr('class').indexOf('clicked') != -1) { $(this).siblings('ul').animate({"top": "35px"}, {queue:false,duration:(500)}, "swing"); } else { $(this).siblings('ul').animate({"top": "0px"}, {queue:false,duration:(500)}, "swing"); } $(this).parent().siblings().removeClass('clicked').find('ul').animate({"top": "0px"}, {queue:false,duration:(500)}, "swing"); } }) $('#menuHolder ul li:not(:has(ul)) a').mouseout(function (event) { if (this == event.target) { $(this).parent().toggleClass('clicked'); $(this).parent().siblings().removeClass('clicked').find('ul').animate({"top": "0px"}, {queue:false,duration:(500)}, "swing"); } }); }); </script> hello, I got this javascript code to avoid bots to fill out with trash the forms I have in my website: <script type="text/javascript"> var a = Math.ceil(Math.random() * 10); var b = Math.ceil(Math.random() * 10); var c = a + b function DrawBotBoot() { document.write("Cuanto es "+ a + " + " + b +"? "); document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>"); } function ValidBotBoot(){ var d = document.getElementById('BotBootInput').value; if (d == c) return true; return false; } </script> <P>Are you human?<br /> <script type="text/javascript">DrawBotBoot()</script> <P> <INPUT id="Button1" name="SUBMIT" TYPE="SUBMIT" VALUE="ENVIAR" onclick="alert(ValidBotBoot());"/> <INPUT name="RESET" TYPE="RESET" VALUE="BORRAR"> My problem is that the form sends itself even if you dont type the correct answer, I would like to Validate first and then allow me to send the form after validation. You can see the form he http://www.futuros.com/mercados_calientes.html feel free to play with it, i know is the only way to actually see what i'm trying to accomplish. Thanks, Alan Hi My html document contain many images which has the attribute src of img tag as the flowing : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg-- All those images has the common source folder http://images.mysite.com/a/p This is an example : PHP Code: <img src = "http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg--" width = "105" height = "73" > I tried during many days to find the solution using RegExp but I didn't arrives. What I want to do is I - change for all image from the seem folder the src attribute to match the exact url of the image without special characters, for this example : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg-- Became : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg II - Control the width and height of the image by changing its height and width attributes resp. from two javascript variables : PHP Code: var v_width = 320 // Just for example var v_height = 250 // Just for example This is an example of try didn't work for me, for the first issue : PHP Code: var element = document.getElementsByTagName("img"); for(var i=0;i<element.length;) { var myString = new String(); var myRegExp = new RegExp("http:\/\/d\.images\.mysite\.com\/a\/p[^\?]*(jpg|png|gif)","i"); var myRegExp0 = new RegExp("\?.*","i"); myString = element[i].getAttribute("src"); if(myRegExp.test(myString)) { var newString = myString.replace(myRegExp0,""); element[i].setAttribute("src",newString); } } Help me please Think you hi, I need to modify IE print settings(paper size, print orientation) automatically, by javascript and can not use ActiveX control or reduce IE security setting. Can any one tell me how to implement this function,Thanks. I am using the simple password script from http://www.allwebco-templates.com/su...ect_simple.htm where the password is contained in the header script. I need to change the password, e.g. from Jan to Feb to Mar to Apr etc. How could I modify the script to contain the list of passwords, and have it automatically utilise/apply the correct password for the current month? To a non-javascript person like me this seems like it should be simple..... Can anyone please suggest a solution? Thanks muchly in advance. Hey guys, wondering if anyone can help me. My JS knowledge is pretty non-existent. Basically I am currently using this code for a day countdown: Code: <script> //change the text below to reflect your own, var before="" var current="" var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") function countdown(yr,m,d){ var today=new Date() var todayy=today.getYear() if (todayy < 1000) todayy+=1900 var todaym=today.getMonth() var todayd=today.getDate() var todaystring=montharray[todaym]+" "+todayd+", "+todayy var futurestring=montharray[m-1]+" "+d+", "+yr var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1) var dstring=difference.toString() if (difference==0) document.write(current) else if (difference>0){ document.write("") for (i=0;i<=dstring.length-1;i++) document.write('<img src="/c'+dstring.charAt(i)+'.png">') document.write('<img src="/days.png">'+before) } } //enter the count down date using the format year/month/day countdown(2011,08,17) </script> I like this script because it outputs in images. As you can see in my site at: http://www.bigbrothersite.co.uk/ (in the header) My question is, can that script above be adapted so it also works as a count up script. For example, from the 17th of august, can i somehow adapt it so i can use it to count up the days? Any help please. Thanks! |