JavaScript - Inserting Javascript
Hello. I have two javascript problems. 1). I have a java script that displays 'What's On Air Now' and 'Today's Schedule' which are located in a 'Resources' folder on our website. I have been using Namo Web Editor for several years but, after many problems, I bought WebPlus X4 from Serif Applications. It's a very good program but I'm having severe problems inserting the Javascripts mentioned above. With Namo, I just had to add: "<script type="text/javascript" src="resources/onair.js"> and the same for 'Today's Programs':"<script type="text/javascript" src="resources/schedule.js">". with WebPlus X4, I've had no luck after trying numerous times and requesting help from Serif who would not help. I would be grateful if anyone could help me, please. Thank you. PS: I have attached the text version of the scripts for you to have a look at.
Similar TutorialsHi, I am using javascript to collect hidden form elements and then send the values to a php page, without reloading or changing the page. Basically i have a list of job vacancies, with just an apply button, when a person clicks on the apply button, the form collects some information from their account and sends it using the javascript code. Now this works fine, except for if somebody then clicks on the second job it sends the information from the first form again. And it seems to remember the information. What i am trying to find out is it possible to have multiple forms on one page which once submitted send variables to javascript which then send them to a php but clear themselves so that it doesn't remember the previous values. Here is the code for the form: Code: <form id="submit" method="post"> <fieldset> <input type="hidden" name="usern" id="usern" value="php variable" /> <input type="hidden" name="joborder_id" id ="joborder_id" value="php variable" /> <input type="hidden" name="site_id" id ="site_id" value="php variable" /> <button class="button positive">Apply For This Job </button> </fieldset> </form> <div class="success" style="display: none;">Your Application has been sent.</div> </form> And the Javascript code is he Code: $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var usern = $('#usern').attr('value'); var joborder_id = $('#joborder_id').attr('value'); var site_id = $('#site_id').attr('value'); $.ajax({ type: "POST", url: "apply.php", data: "usern="+ usern +"& joborder_id="+ joborder_id +"& site_id="+ site_id, success: function(){ $('form#submit').hide(function(){$('div.success').fadeIn();}); } }); return false; }); }); Any ideas or suggestions would be appreciated, Thanks Lee Hello my first post. I have a function that insert commas via onclick or onblur. Code: function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } I also am using code from this link, where I can specify what parameters to allow the user to enter only positive/negative, decimals values and restricting characters that are not allowed. http://www.mredkj.com/tutorials/validate2.html I am having a hard time to incorporate the addCommas function into the link above. Does anyone have an example that I can look at where I can have commas added to a value dynamically while typing? e.g. if I type 1000 after that last 0 keystroke, it turns the value into 1,000. If I add 3 more zeros it turns it into 1,000,000. In the same vain if I subtract a 0 from the 1,000,000 the value is 100,000 instead. I appreciate any assistance in advance. The below code is not inserting the smile into the textbox. In IE8 I get an error around Code: if((sel.type == "Text" || sel.type == "None") && rng != null) In Firefox 3.5 I get an error around: Code: if (es <= 2) Each textarea has: id and name Code: <textarea class="textinput" id="about_me" name="about_me" cols="45" rows="6"> Here is the whole smile code I am using. Code: //Smile Start var myAgent = navigator.userAgent.toLowerCase(); var myVersion = parseInt(navigator.appVersion); var is_ie = ((myAgent.indexOf("msie") != -1) && (myAgent.indexOf("opera") == -1)); var is_nav = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1) && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1) && (myAgent.indexOf('webtv') ==-1) && (myAgent.indexOf('hotjava')==-1)); var is_win = ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1)); var is_mac = (myAgent.indexOf("mac")!=-1); function smile( txt ) { // document.all.txtmessage.value = document.all.txtmessage.value + txt; // return false; doInsert(" " + txt + " ", "", false,document.getElementById('txtmessage')); } function smile2( txt ) { doInsert(" " + txt + " ", "", false,document.getElementById('txttemplate')); } function doInsert(ibTag, ibClsTag, isSingle, name_txt) { var isClose = false; var obj_ta = name_txt; //---------------------------------------- // It's IE! //---------------------------------------- if ( (myVersion >= 4) && is_ie && is_win) // if ( (ua_vers >= 4) && is_ie && is_win) { if (obj_ta.isTextEdit) { obj_ta.focus(); var sel = document.selection; var rng = sel.createRange(); rng.colapse; if((sel.type == "Text" || sel.type == "None") && rng != null) { if(ibClsTag != "" && rng.text.length > 0) ibTag += rng.text + ibClsTag; else if(isSingle) isClose = true; rng.text = ibTag; } } else { //-- mod_bbcode begin // this should work with Mozillas if ( (myVersion >= 4) && is_win) { var length = obj_ta.textLength; var start = obj_ta.selectionStart; var end = obj_ta.selectionEnd; if (end == 1 || end == 2) end = length; var head = obj_ta.value.substring(0,start); var rng = obj_ta.value.substring(start, end); var tail = obj_ta.value.substring(end, length); if( start != end ){ if (ibClsTag != "" && length > 0) ibTag += rng + ibClsTag; else if (isSingle) isClose = true; rng = ibTag; obj_ta.value = head + rng + tail; start = start + rng.length; } else{ if(isSingle) isClose = true; obj_ta.value = head + ibTag + tail; start = start + ibTag.length; } obj_ta.selectionStart = start; obj_ta.selectionEnd = start; } else { //-- mod_bbcode end if(isSingle) { isClose = true; } obj_ta.value += ibTag; //-- mod_bbcode begin } //-- mod_bbcode end } } //---------------------------------------- // It's MOZZY! //---------------------------------------- else if ( obj_ta.selectionEnd ) { var ss = obj_ta.selectionStart; var st = obj_ta.scrollTop; var es = obj_ta.selectionEnd; if (es <= 2) { es = obj_ta.textLength; } var start = (obj_ta.value).substring(0, ss); var middle = (obj_ta.value).substring(ss, es); var end = (obj_ta.value).substring(es, obj_ta.textLength); //----------------------------------- // text range? //----------------------------------- if (obj_ta.selectionEnd - obj_ta.selectionStart > 0) { middle = ibTag + middle + ibClsTag; } else { middle = ibTag + middle; if (isSingle) { isClose = true; } } obj_ta.value = start + middle + end; var cpos = ss + (middle.length); obj_ta.selectionStart = cpos; obj_ta.selectionEnd = cpos; obj_ta.scrollTop = st; } //---------------------------------------- // It's CRAPPY! //---------------------------------------- else { if (isSingle) { isClose = true; } obj_ta.value += ibTag; } obj_ta.focus(); return isClose; } //Smile End I have the need to include an Ad Tag from a third party source that is generated via javascript which document.writes the code to display the ad. I have no control over this. I have it working on my end, BUT for the life of me I cannot get this to center in my div. It's like it busts out and aligns left after my div. I can't fathom what is going on. "IF" I include this ad tag directly in the page inside the div, it centers. But I need to dynamically pass it some data before it requests the ad, so I Have to dynamically create it, but this is the issue. It displays, just aligned left outside the target div. So, I am given a js tag with a src and that src generates a document.write that writes out an iframe. Here is my code below. I take the js src and replace some value in it since it is a string. Then I create a script element and then insert it into my div element on my page. var js_src = ("contents_of_the_src").gsub(/tie=/,'tie=' + random10_digit) var js_script = new Element('script',{'src': js_src}); Event.observe($('myDiv'), 'load', $('myDiv').insert({top : js_script})); so the view in question is something like this: <div id="myDiv"> <script language="text/javascript"> var js_src = ("contents_of_the_src").gsub(/tie=/,'tie=' + random10_digit) var js_script = new Element('script',{'src': js_src}); Event.observe($('myDiv'), 'load', $('myDiv').insert({top : js_script})); </script> </div> I've tried moving the js out of the div, afterwards, and try to insert then. I tried to create a new div, center that, and write the ad tag to it. All left alighned and outside of the div. How would I insert bbc code around selected text in a textbox like it is in this forum? I'm quite new to javascript, so please try to explain it simply Thank you, ~AngelMare Hello, I know very little Javascript, so the answer to this is probably VERY simple :-) I have some javascript working out the current date for me. I want to output this date into the value of an input field in a form. My javascript to output the date is: Code: <script type="text/javascript"> <!-- var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() document.write(month + "/" + day + "/" + year) //--> </script> And I'd like this to output in the value of the input field below: Code: <input type="hidden" name="date" value="js date to go here"/> I've tried using script tags and document.write, but it messes up my HTML and I'm not sure what exactly it is that I'm doing wrong!! Sorry for the silly question... Thanks for your help Nicky So my goal was to insert a mini ICO image (of an R) and have it be a link to an external news page for each individual player on a fantasy team. The code below gets the proper link to each player and inserts the image and corresponding link one at a time though a couple different functions. I have inserted the IMG successfully (see attached), but I am having issues with the link. There are times when the images load accurately with the correct link and others when some of the 'href' elements say undefined. And it isn't consistent either, as to imply that it is a specific coding error. It is completely random and sometimes they are even all correct. Could this have something to do with the asynchronicity of the GM_xmlhttprequests and the loop? If so, is there some way to get around that? This is the bottom of the code which gets fed an array teamURL with all the proper URLs. All of the variables and arrays have the correct information, as they have been checked and double checked. It is almost as if I need a way to slow down the loop to let it do its thing... if that makes any sense. Code: var count = 0; var item = 0; for (var k=0; k< myPlayersArray.length; k++) { GM_xmlhttpRequest({ method:"GET", url:teamURL[k], headers:{"User-Agent":"Mozilla/5.0","Accept":"text/xml"}, onload:function(response){findInfo(response);} }) ; } var allElements = document.evaluate("//*[contains(@href, 'http://sports.yahoo.com/nfl/players/')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); var baseRotoworldURL = 'http://www.rotoworld.com'; function findInfo( response ) { var doc = document.createElement( "div" ) ; doc.innerHTML = response.responseText ; //Get appropriate td data on the rankings page var teamPageList = document.evaluate("//a[contains(@href, 'player')]",doc,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); for (var m=0; m<teamPageList.snapshotLength; m++) { if ((teamPageList.snapshotItem(m).innerHTML.toString()) == (myPlayersArray[count].toString())) { var playerHTML = teamPageList.snapshotItem(m).parentNode.innerHTML; var match = playerHTML.match(/\/nfl\/\d{1,10}\/[a-z]+\-[a-z]+/); var playerURL = baseRotoworldURL +"/recent" + match break; //loop until you get a hit } } addGameLogIcon(allElements, playerURL); count++; } function addGameLogIcon(allElements, playerURL) { var thisElement; var rotoworldLink; var rotoworldLinkGraphic = "data:image/gif;base64,"+"AAABAAEADw8AAAEAGAA0AwAAFgAAACgAAAAPAAAAHgAAAAEAGAAAAAAAAAAAAEgAAABIAAAAAAAAAAAAAADR09TR09TR0tPR0tPQ0tPQ0tPQ0tPQ0dTQ0tPQ0tPQ0tPQ0dPQ0tPR09TR09S9AADR09TR09TP0dOvssuan8acocfFx9HQ0tPGyNGdocean8edocfDxdDR09TR09S9AADR09TR09TGydFHRsEsKNsrJ9SGicLP0dNsb74rJ9csKNsrJ8iTlcPR09TR09S9AADR09TR09TEx9BFRcYvKu0sKOOChcK3ucwuKsgvKu0uKedUVMDIydHR09TR09S9AADR09TR09TEx9BERMQuKOcsJ9+ChcFnaLstJ+IuKOc0McuqrMnQ0tTR09TR09S9AADR09TR09TEx9BERMItKOEsJ9lfYbYuKsQtKOEsJ9hxc7/P0NPQ0tPR09TR09S9AADR09TR09TEx9BERMAsJ9srJ9gqJsgrJ9ksJ9sqJsdub7vJytHQ0tPR09TR09S9AADR09TR09TEx9BEQ70sJ9QsJ9UsJtQsJ9QsJtUsJtQrJspzdb3Q0dPR09TR09S9AADR09TR09TEx9BEQ7stJc4sJco8OrZJSLkxLbotJc0tJs49Ori/wM7R09TR09S9AADR09TR09TEx9BDQ7ksJ8gsJsN6fL3Bw855e7wrJcIsJ8c5Nrm7vs3R09TR09S9AADR09TR09TEx9BEQ7YtJ8IsJ780MLE+O7QuKrYsJ8EtJ8I/PLTBws/R09TR09S9AADR09TR09TEx9BERLUtKMEtKMEtJ8EtJ8EtJ8AsJ8EtKLh7fL3P0NTR09TR09S9AADR09TR09THytFMTrQpJrUpJrUpJrUpJrUvLrVGRLSKisDLzNLQ0tTR09TR09S9AADR09TR09TR09TDxdC7vc67vc67vc67vc6+wc/HytHR09TR09TR09TR09TR09S9AADR09TR09TR09TR09TR09TR09TR09TR09TR09TR09TR09TR09TR09TR09TR09S9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; thisElement = allElements.snapshotItem(item); rotoworldLink = document.createElement('a'); rotoworldLink.setAttribute("href", playerURL); rotoworldLink.setAttribute("target","_blank"); rotoworldLink.innerHTML = "<img border='0' src='" + rotoworldLinkGraphic +"'>" ; thisElement.parentNode.appendChild(rotoworldLink, thisElement.nextSibling); item=item+3; } I have a table with two rows and 4 columns, the first cell has rowspan of 2. How do I insert something into the first cell only? How can I get the cell index of the first cell?
First off: I know nothing of Javascript (or much of any coding really), but I expect this to be simple for someone experienced, although it was (suprisingly) hard to figure out, for a lousy Googler like myself; so here I am. I have a function that generates an URL to an image, as so: Code: function todaysDate() { var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() window.location.href = "http://www.ecample.com/generator.aspx?format=png&month="+month+ "&day="+day+"&width=320&height=480" } I get the image displayed fine in a new window, but I need it to open in a <div> or object, iframe, something I can place under my <div>-based header, when a button is pressed from my menu. Code: <div id="image"> <div class="header"> <a href="#" class="back">back</a> <h1>Title</h1> </div> I WANT IT HERE! </div> Any help would be greatly appreciated! Regards, Andrew. Hi, I am sending some information from one page to another using Form and Link. This generates a string of text in the receiving url, which I am extracting and displaying in a textarea. How do I insert a linebreak in the javascript code? With this line of code: document.getElementById("Requirements").value = "Top line: "+ topline + "Your breakfast contains: "+ menuitems; everything that is being returned is running together. I need it to run on separate lines. I can't control it with box width because the entries will vary on each occasion. I assume there is an escape character like in php or a break tag like in HTML, but I don't know what it is! Any help appreciated. Thanks, Tim Hi im new to this site and im a begginer, so forgive me for any grammatical errors please. How would I go about running a program onclick or onblur and displaying the result on same page without it changing? I am trying to insert a new paragraph with javascript, however my code is not working, even though i pretty much copied my code from the book. Could someone please tell me why i have a problem with a script below? Thank you very much. <script type="text/javascript"> function newtext() { var myPara=document.createElement("p"); var text="We sincerely hope that you are enjoying learning Javascript"; var paratext=document.createTextNode(text); myPara.appendChild(paratext); } </script> <p> <a href="#" onclick="newtext()"; return: true;> Insert new text </a> </p> Hi all, I have: Code: var moreinfo =""; moreinfo+= "here some content"; $("#divMoreInfo").html(moreinfo); And this inserts "here some content" in a div called divMoreInfo. Now divMoreInfo is placed inside an iframe while the rest of the programming has to be in the parent page... How do I insert moreinfo's contents in the iframe's div?? Thanks a lot Hello, I need your help, I would to like to insert some styled text into an HTML document using innerHTML and a Div. What would be the code to insert some text with a different font, size and color? Any help is appreciated. Thanks, J I'm trying to insert a form into a div, based on what the user selects in another select form. I'm getting an error whenever I try typing my code. I'm doing this in Dreamweaver and it highlights my text green (starting at the first /td and ending at the next / of the next /td) Will adding this form even function properly when I send? Any ideas on what's going on? Thanks Code: function showTable(y) { if(y == "readers") { document.getElementById("next").innerHTML = "<form id='readersTable'> <table> <tr> <td>Attribute 1</td> <td><input type='text' name='at1'> </td> </tr> </table> </form>" } @ http://jsfiddle.net/defencedog/cu5VJ/ I am having problem in understanding the operation of js with regards to this line Code: $('.' + x[i].id).text(x[i].innerHTML); or Code: $('.' + x[i].id).html(x[i].innerHTML); I want to understand why I ain't able to produce desired results while using this instead Code: $('.' + x[i].id).innerHTML(x[i].innerHTML); What i'm trying to do is, insert a file upload input into HTML, depending on dropdown menu selection. I have a form, where you enter your email and a message. What i'm trying to add now is, a dropdown menu which will select type of message, with 4 options. If 3rd or 4th option is selected, a <input type="file"> will be inserted under the message box. I also don't want the page to refresh. here's the code i have now: Code: <form action="zahteva.php" name="naroci" method="POST"> <label>Your email:</label> <input id="text" type="text" name="email" autocomplete="off"> <br /> <label>Type</label> <select name="type"> <option value="1">1st (no file upload)</option> <option value="2">2nd (no file upload)</option> <option value="3">3rd (file upload)</option> <option value="4">4th (file upload)</option> </select> <label>Message:</label> <textarea id="txtrea" name="sporocilo"></textarea> <br /> <!-- <label>File:</label> <input type="file" name="file"> only show this part if 3rd of 4th is selected --> <input id="gump" type="submit" value="Send"></td> </form> Hey. Yes, I'm just starting at the beginning and what I'm trying to understand today is adding special characters such as line break, quotes, etc. into Javascript. I'm missing something, however. Can someone please assist? What I'm trying to do is add a line break without having it show /n on the screen. My Code: <html> <head> <title>Exercise 6-20</title> </head> <body><pre> ********* *** * *\n * * * * *** * *\n * * * * ***** * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n ********* *** * * *\n </pre> </body> </html> Thank you, H Code: var ip = '<!--#echo var="REMOTE_ADDR"-->'; xmlhttp.open("GET","getuser.php?q="+str+"&ip="+ip,true); xmlhttp.send(); I'm sending the above via a GET to a php file that inserts into a DB. here is the php portion Code: <?php $q=$_GET["q"]; $ip=$_GET["ip"]; $sql="INSERT INTO statcounter (selection, ip) VALUES ('".$q."','".$ip."')"; It is inserting properly into the DB, but the IP isn't correct. In the IP field I'm getting "<!--" instead of the users IP address. Would anyone have any advice on this? I took the first line from this website http://javascriptsource.com/user-det...p-address.html Apparently they were able to get the IP from only using var ip = '<!--#echo var="REMOTE_ADDR"-->'; But I'm not sure how they were able to do this |