JavaScript - Passing Javascript Replace Function As An Argument Of User Defined Function
Hi,
I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, Similar TutorialsHello, I am trying to execute a javascript function passed as argument. I am not sure of the exact way to do it. <html> <head> <script type="text/javascript"> var checkLink = function(linkId, enabledFunction){ var linkidObj = document.getElementById(linkId); if(linkidObj.className=="activelinktext" ) { enabledFunction(); return false; } else if(linkidObj.className=="inactivelinktext") { return false; } alert("*inside CheckLink*"+enabledFunction); }; </script> </head> <body> <a class="inactivelinktext" onclick="checklink(this,"javascript:goback();")"> </body> </html> Thanks, -Vijay I am trying to use a user defined function and text area for a project, but nothing is showing up in the text area when i click the button. Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> function Greet() // Assumes: firstNameBox and companyName contain names // Results: writes a message with those names in messageArea { firstName = document.getElementById("firstNameBox").value; companyName = document.getElementById("companyNameBox").value; message = "To whom it may concern, my name is " + firstName + ", I am very interested in the job opening at, " + compnayName + ". I feel that I would greatly contribute to " + companyName + " success. I feel I fit the requirements needed to become an employee at " + companyName + ". I look forward to hearing from you."; document.getElementById("messageArea").value = message; } </script> </head> <body> <p> Enter your first name: <input type="text" id="firstNameBox" size="15" /> <br /> Enter the Company name: <input type="text" id="companyNameBox" size="15" /> </p> <p> <input type="button" value="Click for Greeting" onclick="Greet();" /> </p> <p> <textarea id="messageArea" rows="4" cols="40"></textarea> </p> </body> Hi guys , i have this function that allows me to hide a <div ID="ID1"> . function hide(X) { document.getElementById('X').style.visibility='hidden'; } <p><a href="#" onclick="hide('ID1');">show me/</a></p> <div ID="ID1" style="visibility:hidden">This is the content</div> the issue the function only works when i change X by ID1. i want to make it for any ID called with the function by assigning any DIV "ID" as an argument. any help ? thanks Hi, I have a button that when you click it displays the results of my db in a div. What I am trying to do is to get the results to update every five seconds. I thought setTimeout was the best way to achieve this. However I am getting the error message that ID is not defined on the setTimeout line. I thought it would automatically input ID into the fields marked ID when the onloadXMLDocRefresh('File.php','txtHint') button is clicked? The button works to load the script, but the refreshing the div is not. My script is: Code: <script type="text/javascript"> function loadXMLDocRefresh(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; timer = setTimeout('loadXMLDocRefresh(File,ID)',5000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> Ok, guys. I'm new to JavaScript, so go easy. I'll be asking bunches of "dumb" questions for a while. 1st question, and the only one for now ... Say I have the following function: Code: function SwapValues(SwapVal1,SwapVal2) { TempSwapVal=SwapVal1; SwapVal1=SwapVal2; SwapVal2=TempSwapVal; } I don't care about the return value of the function itself, but I do need the new values of SwapVal1 and SwapVal2. In ASP when I do this, the values get returned. How do I get this to work in JS? i keep getting error Call to undefined function codeandurl() below is my code PHP Code: <?php $value= strip_tags(get_field('link',$post)); $resultid=get_field('resultid',$post); codeandurl($resultid,$value); ?> <div id="result"></div> <script type="text/javascript"> function codeandurl(resultid,url){ $( "#result" ).text(resultid); $( "#result" ).dialog({ modal: true, buttons: { Ok: function() { $( this ).dialog( "close" ); } } }); window.open(url); return false; } </script> Code: s = s.replace(/\[code\](.*?)\[\/code\]/gi,'<span class="code">$1</span>'); This works as expected, but what I'm trying to do is replace the content within the tags with a santized version of what was in it before. Example Code: function clean(str){ //clean up string stuff here return str; } s = s.replace(/\[code\](.*?)\[\/code\]/gi,'<span class="code">'+clean('$1')+'</span>'); But as with everything in life it's never that easy, it's simply passing "$1" to the clean function instead of what was actually within the code tags. Can anyone tell me how I'd go about doing this? I have a js replace function to replace text next to two radio buttons on a pre set form. Script is as follows. Code: document.body.innerHTML = document.body.innerHTML.replace( "Payment by <b>Moneybookers</b> e-wallet<br>", "" ); document.body.innerHTML = document.body.innerHTML.replace( "Maestro, Visa and other credit/debit cards by <b>Moneybookers</b>", "Pago con Diners Club, Mastercard o Visa" ); The script works fine in Chrome and Firefox, however, the script is not actioned in Explorer. I believe it has something to do with there being , / - within the text I am replacing? When I use the function to replace text with no , / - in the text - it works fine in explorer, however, for example when I try to replace text.. - "Maestro, Visa and other credit/debit cards by Moneybookers" this does not work in explorer.. I'm assuming because of the coma and forward slash. Honestly I've tried everything but just can not get this to work. I have no access to the HTML table where the form is posted this is why I am attempting this funtion. Any help would be greatly appreciated!! I'm trying to make it so when you click a cell in a table it runs a function based on the value within that cell. With the current code, no matter what cell is clicked, the alert box displays the same number, which is the last number in my array. The variable, princ, is just being overwritten rather than writing code to each the cell with the proper value. Help is appreciated. Thanks. Code: for(i=0;i<=3;i++){ document.writeln('<tr>'); document.writeln('<th>'+(periodArray[i])+'</th>'); for(j=0;j<=2;j++){ princ = principleArray[j][i]; document.writeln('<td onclick="(calculateInterest(princ,1,1))">$'+principleArray[j][i]+'</td>'); } document.writeln('</tr>'); } function calculateInterest(principle,rate,period){ totalInterest = principle * rate * period; totalLoanCost = principle + totalInterest; alert('Total Interest: '+totalInterest+'\n'+'Total Loan Cost: '+totalLoanCost); } I want to pass dynamic array values to java script function.how its possible. explain with some code.........
First off I didn't know whether to post this here or in the PHP section since it deals with both, but mostly JS. I have a PHP scraper that scrapes the job title, company name and location from a website and stores them in separate arrays. These values are then extracted out one at a time from the array and stored into a string, that is then passed to a Google Maps API. I can make this successfully happen once, the thing is I need to do it multiple times. I have an idea on what I should do but don't really know how to implement it (correctly). The idea I had was to create a function in the JavaScript section that accepts three values from PHP. This function would be called in my PHP for loop that extracts the values from the array into a string. The thing that confuses me is that the Map function is called via <body onLoad="initialize()">. Here's the link to my code Thank you in advance if someone can help. I have been banging my head against the wall for hours now. Here is the code: Code: for (var i = 0; i < BS_crm['activityTypes'].length; i++) { var clickFunc = function(){ activityList.showForm( -1, {blockType:[""+BS_crm['activityTypes'][i]['id'], "0"]} ); }; var type = { value: BS_crm['activityTypes'][i]['id'], label: "Add New "+BS_crm['activityTypes'][i]['label'], css: BS_crm['activityTypes'][i]['css']+"_16", onClick: clickFunc }; previewLinks.items.push( type ); } Now, basically what I am doing here is running through one array to create an array of objects, that will be used to create links that will use whatever onClick function I pass it. The problem is that on the second line I need the BS_crm['activityTypes'][i]['id'] to be a value, not a reference. If that line was simply changed to: Code: var clickFunc = function(){ activityList.showForm( -1, {blockType:["3", "0"]} ); }; then everything would work as I need. How can I make this happen? I would really appreciate any help. Thank you again in advance. Hi, Any one help me In one variable i have some data ex: var data = document.getElementById("imageId").value; I want to pass this data to another function inside another function ex: var button1 = '<img src="images/Remove-button.gif" width="70" height="15" onclick="removeVerifyImageRow(this),saveLibData('+data+')"/>'; while running the application i am getting an error incase if the data is string ex:if data is 'image1' i am getting an error, but with number there is no problem ex: if data is '1122'. this is very urgent to solve this problem plz any one help me JavaScript: Code: function test() { alert('dsd'); } HTML: Code: <a href="#" onClick="test()">Test Link</a> JS Error: Code: Error ``ReferenceError: test is not defined'' [x-] in file ``file:///C:/Users/Martyn%20Ball/Desktop/test.php#'', line 1, character 0. Okay wtf. Here is my function: Code: function mod_selection(val1,val2) { if( -1 != navigator.userAgent.indexOf ("MSIE") ) { var range = document.selection.createRange(); var stored_range = range.duplicate(); if(stored_range.length > 0) { stored_range.moveToElementText(textArea); stored_range.setEndPoint('EndToEnd', range); textArea.selectionStart = stored_range.text.length - range.text.length; textArea.selectionEnd = textArea.selectionStart + range.text.length; } alert('hi'); // Get the text area var textArea = $("#text_edit"); textArea.hover(function() {alert('hi');}) // Do we even have a selection? if (typeof(textArea.selectionStart) != "undefined") { // Split the text in three pieces - the selection, and what comes before and after. 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); // Insert the tags between the three pieces of text. textArea.value = begin + val1 + selection + val2 + end; } } } Basically what it does is insert BBCode tags for whatever text you have highlighted. Here is my HTML for it: Code: <div class="two-row"> <label>Content: </label> <a href="#" onclick="mod_selection('','');return false;">B</a> <input type="button" value="I" onclick="mod_selection('','')" /> <input type="button" value="U" onclick="mod_selection('','')" /><br /> <textarea id="text_edit" name="body" rows="25" cols="51"><?php if(isset($_POST['submit']) || isset($_POST['preview'])) { echo $_POST['body']; }else { echo $news_body; } ?></textarea> </div> It says the mod_selection is not defined. I'm doing alert('hi'); for testing purposes and it won't print hi.. sooooo I feel like I need a second pair of eyes. I want it to at least recognize the function before I debug it any further. Ok, I have an event handler for a click - ala: using prototype and here is a snippet. Code: spotL = some_length_of_an_array; $R(1,spotL).each(function(n) { $('spot_btn_' + n).style.display = 'block'; $('spot_btn_' + n).observe("click", function(){countdwn_clear();} ); }); Now, that code above fires off AFTER I call an init function that just runs thru some things... But not only that, that function "countdwn_clear()" loads before I call the code above... so its there. Now, the "element" I am trying to attach that event handler in an anchor tag in a UL element ala. Code: <ul id="buttons" style="display: none;"> <li id="spot_btn_1" class="selected"><a href="javascript://" id="btn1">1</a></li> <li id="spot_btn_2"><a href="javascript://" id="btn2">2</a></li> </ul> so, I originally thought it that I was trying to attach an event handler to an element in another that had a display of none -- so I switched it to block and I'd still get this error: countdwn_clear is not defined NOW -- if put this right below the function call, ala: Code: function countdwn_clear(){d_some_code_here} $$("#buttons li")[0].observe("click", function(){countdwn_clear();} ); $$("#buttons li")[1].observe("click", function(){countdwn_clear();} ); ^^^^ that works! why? In one case, i am calling it right below the function and I am using a different reference: $$("#buttons li")[1] in the code where I "build" it, I have: $('spot_btn_' + n).observe("click", function(){countdwn_clear();} ); ???? could it be the event is on the "li" instead of the "a" or ? I don't get it. Any ideas? Hi guys my site is not working fireug says that the function 'changevalu()' ia not defined but it is heres my site Code: <!doctype html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html" > <title> portl - beta 0.1 </title> <meta name="description" content="portl Is a file transfer system. "> <meta name="author" content="Techyonomics"> <meta name="viewport" content="width=device-width"> <meta name="keywords" content="portl,techyonomics,school,free,privet,trans,files,ui,cool" > <link rel="stylesheet" href="style.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="javascript/text"> function changevalu() { var valueofpress = $(this).text(); var passval = $(#password).val(); $(#password).val(passval + valueofpress); alert(passval + valueofpress); } </script> </head> <body> <header> </header> <div role="main"> <div id="keypad"> <div id="keys"> <div class="key" onmouseup="javascript:changevalu()">1</div> <div class="key">2</div> <div class="key">3</div> </br> </br> </br> <div class="key">4</div> <div class="key">5</div> <div class="key">6</div> </br> </br> </br> <div class="key">7</div> <div class="key">8</div> <div class="key">9</div> </br> </br> </br> <div class="key">C</div> <div class="key">0</div> <div class="key">E</div> </div> <form id="hiddenform" action="login.php" method="post"> <input id="password" type="text" value="" name="pass"></form> </div> </div> <footer> </footer> </body> </html> In jquery-1.4.2.js I find the following - - - hide: function( speed, callback ) { ... } - - - Where is this syntax defined? ... and is it semantically different than - - - function hide( speed, callback ) { ... } - - - I've been working on a web-site and I've run into a problem. None of the buttons I've created will access the functions that they're supposed to access. When I used the JavaScript console in Chrome it threw the error Uncaught ReferenceError: (function) is not defined I've looked over it for syntax errors, but I couldn't find any. Am I missing anything? Here's my unfinished code: 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=iso-8859-1" /> <title>N Physics</title> <script type="text/javascript"> var numforms = 0; var curentform = 0; //consider further editing function reset() { window.location.reload(); } function addvar() { currentform = numforms + 1; selectscreen(); } function changevar() { } function selectscreen() { selectdiv = document.createElement('div'); selectdiv.id = "select"; tkdklskjksdkfj variable = document.createElement('SELECT'); variable.setAttribute('Name', 'variable'); variable.id = "variable"; ForceReg = document.createElement('option'); ForceReg.value = '001'; ForceReg.appendChild(document.createTextNode('Force')); variable.appendChild(ForceReg); Mass = document.createElement('option'); Mass.value = '002'; Mass.appendChild(document.createTextNode('Mass')); variable.appendChild(Mass); Accelleration = document.createElement('option'); Accelleration.value = '003'; Accelleration.appendChild(document.createTextNode('Accelleration')); variable.appendChild(Accelleration); selectdiv.appendChild(variable); document.body.appendChild(selectdiv); } function newform() { } function cancel() { } function deleteform() { } fucntion checkprimary() { } function findeq() { } </script> <style type="text/css"> <!-- body { background-color:#999999; } #LayerHead { position:absolute; left:0px; top:0px; width:100%; height:50px; z-index:1; background-color: #000000; } .spacer { height:51px; z-index:0; } .Button { height:50px; z-index:2; } .style1 { color: #FFFFFF; font-size: 43px; z-index:1; } .style2 { color: #FFFFFF; font-size: 10px; z-index:3; } #LeftButton { width: 49%; height: 50px; left: 0px; z-index:2; } #RightButton { width: 49%; height: 50px; right: 0px; z-index:2; } #Bottom { position:fixed; background-color:#000000; width:100%; bottom: 0px; left: 0px; z-index:3; } #select { position: fixed; width: 100%; height: 100%; opacity: 0.7; filter: aplha(opacity=40); background-color:#333333; } #variable { position: fixed; top: 50%; width: 90%; margin-left: auto; margin-right: auto; } --> </style> </head> <body> <div id="LayerHead"> <span class="style1">N Physics</span> </div> <div class="spacer"></div> <div class="Button"> <input type="button" id="LeftButton" value="Instructions" onclick="location.href = 'instructions.html'" /> <input type="button" id="RightButton" value="Reset" onclick="reset();" /> </div> <div id="VarDone"></div> <div class="Button"> <input type="button" id="LeftButton" value="Add a New Variable" onclick="addvar();" /> <input type="button" id="RightButton" value="Find the Equation" onclick="findeq();" /> </div> <div id="Answer"></div> <div id="Bottom"> </div> </body> </html> I have a good understanding of javascript although I am new to working xml. So I am having a problem getting javascript to recognize that my parameter value in my function call is an attribute in my xml. I called the js function like this: Code: <a href="#" onClick="ebookCategory(marketing);">Marketing</a> Here is my js function: Code: var category; function ebookCategory(category) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","ebook.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName(category); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("bookCover")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue); document.write("</td><td>"); i++; document.write(x[i].getElementsByTagName("bookCover")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); } // end ebookCategory() Some of the aspects in this function are new to me, xml stuff. Here is my xml setup: Code: <ebook category="marketing"> <bookCover><img src="/millionaire/ebooks/covers/miracle2.jpg" height="150" width="150" /></bookCover> <title>Marketing Miracle</title> </ebook> I appreciate any help in the matter |