JavaScript - Passing Parameters From Embedded Javascript
Hi,
This is a noob question which I've searched all over for but can't find an answer..........which means it probably isn't possible Can I pass a parameter to a javascript function from embedded javascript? I have a function in a separate .js file which accepts a parameter as follows: function initialize(menu){ alert(menu); } When I use the following javascript embedded in my HTML it doesn't work: <SCRIPT LANGUAGE="javascript"> <!-- window.onload = initialize('testMenu'); // --> </SCRIPT> Am I doing something wrong or is this not possible? Thanks for your help Similar TutorialsI am trying to pass a value using a parameter in html (asp) to a javascript function. When I try to pass a value inside of a variable <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1(tst);"> it simply doesn't work (no error msg - just nothing) while if I put a value in the call <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1('5393');"> it works fine. The javascript looks like this: function OnButton1(tst) { var pth = "youth_edit3.asp?cIndex=" + tst; document.YouthEdit.action = pth; document.YouthEdit.submit(); // Submit the page } I've set tst = "5393" but it won't work when I try to pass it. Only a literal value of '5393' works. What am I doing wrong? Thank you in advance. Dear all, I'm passing the variables myTitle and myLink to form.php using javascript. This is the way I'm doing it: Code: <a href='form.php?title=" + myTitle +"&link="+myLink+">Click me</a> It's working great but sometimes myTitle and myLink contain the plus character (+). When this happens it's not passed. In the case of the title, it's just a problem of looks but in the case of the link, well, the link won't work without the character. As an example if the title is: Laptop + Accessories What is passed is: Laptop Accessories What can I do to pass also the plus character?? Thanks a lot!! Code: function viewDetails(rowid,linkid){ alert("enterining into bundles"); if(linkid=='seobundles') { alert("enetering into if "); document.chwAnnouncementW.action='${contextPath}'+"/dolphin.wss/viewSeobundleW?rowindex="+rowid; document.chwAnnouncementW.submit(); } else { alert(linkid); document.chwAnnouncementW.action='${contextPath}'+"/dolphin.wss/viewSeoW?rowindex="+rowid; document.chwAnnouncementW.submit(); } } Actually i am passing linkid="seobundles" as string but its not interpreting and it is always going to else part and not if part. I tried to print link id its teling its of object HTML table type and we are passing the two parameters rowid, linkid from a macro. rowid is working fine as and when we select radio buttion but linkid is not working as an string. IF i pur linkid in single quotes then also its not working I am passing parameters from one page (actually from a frame within a frameset) to another using Javascript. Typically the code is as follows, taking values from a Form. Code: parent.titleFrame.location="frm_right_demo_title.html?MyDateEvent.value='"+ytt+ "'&MyParam_spec.value='"+parent.mainFrame.document.forms.myForm.MyParam_spec.value+"'"; This has worked fine in all browsers including IE, Chrome and Firefox version 2.0.0.2. However, I have now found that it doesn't work with Firefox version 3.6.12. This is because when retrieving the parameters in the new loaded page, the character ' (quote) has been converted to %27 (percent twenty seven). I can write code to replace %27 with the quote character. However, this is lengthy and time-consuming (as I need to have cyclic code as the javascript replace command seems to work only on the first occurrence within a string). Can someone please help me to understand why this is happening and how to overcome it? I have added an event listener to a LI item in the DOM: liNode.addEventListener("mouseover", mouseOn, true); The mouseOn function: function mouseOn(e) { // Test for IE or Firefox var e = (!e)?window.event:e; var yPos; if (e.pageY) { yPos = e.pageY; } else { yPos = e.clientY; } } I would like to pass in another parameter to the mouseOn function in addition to the event that is passed in automatically. Is there a way to do this? [CODE]<script type="text/javascript" src="http://www.avalidsite.com/FlashRules.js" DOMSET = "IC"; GMPNT = "500"; LUCKYB = "TRUE"; CUBAN = "TRUE";> </script>[CODE] What the heck is wrong with the above snippet? When the JavaScript is invoked the values that have been entered for the variables are not present. If I try to reference the value of "DOMSET" for example it is shown to be "undefined"??? Hi, I have a website with several pages. Each page having the same menu. I need one of this menu item's text to vary according to each of my customers, where the customer id will be passed from an external link at launch time. I also need to change the menu item link <a href.../a> dynamically. I'm planning to create a redir.html pacge for each client and within that page, I can insert a url with parameters to launch the main page. Any clue more than welcome! Hi all, I've written the following script: Code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Keys2</title> <script type="text/javascript"> function keyPress(key){ document.getElementById('rect01').style.fill = "red"; } </script> <style> .button { width: 100px; padding-right:10px; height:2em; background-color:#FC3; border-radius:3px; color:#fff; font-weight:bold; } ul { list-style-type: none; padding: 0; margin-left:25px; } li { float:left; width:30px; margin-right:25px; padding:10px; height:2em; background-color:#FC3; font-size:xx-large; } </style> </head> <body> <div> <svg width="1000" height="200"> <rect x="25" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect01"/> <rect x="100" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect02"/> <rect x="175" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect03"/> <rect x="250" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect04"/> <rect x="325" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect05"/> <rect x="400" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect06"/> <rect x="475" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect07"/> <rect x="550" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect08"/> </svg> </div> <div> <ul> <li><a href="#" class="button" onClick="keyPress(rect01);">A</a></li> <li><a href="#" class="button" onClick="keyPress(rect02);">B</a></li> <li><a href="#" class="button" onClick="keyPress(rect03);">C</a></li> <li><a href="#" class="button" onClick="keyPress(rect04);">D</a></li> <li><a href="#" class="button" onClick="keyPress(rect05);">E</a></li> <li><a href="#" class="button" onClick="keyPress(rect06);">F</a></li> <li><a href="#" class="button" onClick="keyPress(rect07);">G</a></li> <li><a href="#" class="button" onClick="keyPress(rect08);">H</a></li> </ul> </div> </body> </html> Now, I could write a version of the keypress function for each rectangle, but that seems like poor coding. Can anyone point out how I might restructure the function or the code so that I can pass the number in the onClick to the rectangle it refers to? Thanks Hi, I need to have a forced focus on a password field which is in an embedded JSP (<%@ include file="password.jsp" %>, this password.jsp doesnt has any body or form tag). I am facing some wierd issues in achieving as desired. The below code (in the parent JSP) DOESNT WORKS: window.onload = function() { document.<formname>.<fieldname>.focus() } here <fieldname> is in password.jsp and not the parent jsp when changed as below IT WORKS(obviously with an alert box which i dont want): window.onload = function() { alert("hi") document.<formname>.<fieldname>.focus() } i cannot use <body onLoad> due to third party javascript component constraints Help please... Firstly let me say, im relatively new to Javascript so im still picking things up.. I have a website that i want to add several mp3's onto. When a user clicks a link i wanted to make javascript change the streaming audio to the one that was selected. My HTML is as follows.. Code: <table style="background-color:Black; color:gold; font-weight:700; font-size:16px"> <tr onClick="Click('http://www.m-hops.co.uk/Music/Motown Flavours.mp3')"><td> 1. Motown Flavours </td></tr> <tr onClick="Click('http://www.m-hops.co.uk/Music/All_Around_The_World.mp3')"><td> 2. All Around The World </td></tr> <tr><td> <OBJECT ID="MediaPlayer" WIDTH="290" HEIGHT="50" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject"> <PARAM id="TRACK" name="FileName" value="http://www.m-hops.co.uk/Music/Motown Flavours.mp3"> <PARAM name="autostart" value="true"> <PARAM name="ShowControls" value="true"> <param name="ShowStatusBar" value="true"> <EMBED id="sound" TYPE="application/x-mplayer2" src="" NAME="MediaPlayer" WIDTH="290" HEIGHT="50" ShowControls="1" ShowStatusBar="1" autostart="1"> </EMBED> </OBJECT> </td></tr> </table> and my Javascript is.. Code: <script language="javascript" type="text/javascript"> function Click(track) { document.getElementById('TRACK').value = track; window.alert(document.getElementById('TRACK').value); } </script> It appears that the right track is being parsed to the javascript but its not changing the audio thats being played. Any ideas?? Hi all, I am rather stuck with the following code and am finding it tough to find resources to help me. I am new to DOM functions and any explanation would be much appreciated! Code: var DATE = {date: xxx, layers: {top: 'topLayer' }, ids: [xxx], go: function() {} }; I also need to add a function to the variable 'DATE' so that it can register DOM events, then modify 'DATE' so that it adds another name-value pair to layers on page. I have been trying to working this out for 24 hours now and am very confused. Any support would be awesome! Thank you! Hello, I'm trying to pass a query from my URL into a <script> using Javascript. THe URL would be formatted like this http://www.FakeSite.com/index.html?zip=12345 The script i want to pass the 12345 into is Code: <script type="text/javascript"> /* / Full Data - Form + TY Page Clicks */ var MediaAlphaExchange = { "type": "ad_unit", "placement_id": "ijX_k5FQsJfYjjaLLbfeJcKzT7NQow", "version": "17", "sub_1": "test sub id", "data": { "zip": "90210" } }; </script> <script src="//insurance.mediaalpha.com/js/serve.js"></script> The 90210 should automattically turn into 12345 Can someone show me the exact code to use to make this happen? Reply With Quote 12-29-2014, 03:12 AM #2 sunfighter View Profile View Forum Posts Senior Coder Join Date Jan 2011 Location Missouri Posts 4,830 Thanks 25 Thanked 672 Times in 671 Posts This is a bit of trickery Code: <!DOCTYPE html> <html> <head> <title>New document</title> </head> <body> <form name="joe"> <input type="hidden" name="burns"> </form> <script> /* These 3 lines put the url of this page into the hidden field of a form no one can see */ var locate = window.location; document.joe.burns.value = locate; var text = document.joe.burns.value; alert(delineate2(text)); // This line calls the next function and shows you what it returns. You should be able to sub this to put the return into your code. function delineate2(str){ point = str.lastIndexOf("="); return(str.substring(point + 1, str.length)); } </script> </body> </html> Hello Guys, I have a page with thumb nails and a large image that changes when clicking on thumbnail. I need to display dynamic title for the image. It wont display because the page is not reloading.. How do you pass the name so it will show up without reloading? Here is the JS for switching dynamically loading the large image PHP Code: <script language="javascript"> $(document).ready(function() { $('.thumbnail').live("click", function() { $('#mainImage').hide(); $('#atitle').hide(); $('#imageWrap').css('background-image', "url('/images/ajax-loader.gif')"); var i = $('<img />').attr('src',this.href).load(function() { $('#mainImage').attr('src', i.attr('src')); $('#imageWrap').css('background-image', 'none'); $('#mainImage').fadeIn(); $('#atitle').fadeIn(); }); return false; }); }); </script> Here is the link for the thumb PHP Code: // Thumbnail Display echo '<a href="artists/'.$artist.'/'.$imgname.'.jpg" class="thumbnail"><img src="artists/'.$artist.'/previews/'.$imgname.'.jpg" border="0" /></a>'; [/PHP] Link to the large image PHP Code: // Large image display echo '<img src="artists/'.$artist.'/'.$first_image.'.jpg" alt="Main Image" id="mainImage"/>'; Here is the php echo for the title PHP Code: <? echo str_replace('"', '`', $iname); ?> I need to some how pass a php var from the thumb link to the js and have it display dynamically(without reloading) Hope I explained this correctly.. Please advise.. Thanks, Dan i've got a project to be done using javascript and html....i don't know how to pass the arguments from <input type="text"> to the javascript function i'm using in my program. i just want the javascript script to calculate the input given by the user and return the answer. here is the program: Code: <html> <head> <title> Taxi Fare </title> <script lang="text/javascript"> // calculates taxi fare based upon miles traveled // and the hour of the day in military time (0-23). var taxiFare = function (milesTraveled, pickupTime) { var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var cost = baseFare + (costPerMile * milesTraveled); // add the nightSurcharge to the cost if it is after // 8pm or before 6am if (pickupTime >= 20 || pickupTime < 6) { cost += nightSurcharge; } return cost; }; </script> </head> <body> <form> <input type="text" onclick="taxiFare()" value="Call function"> <input type="Submit" value="OK" onclick="taxiFare()"> <input type="reset" value="Clear"> </form> <script type="text/javascript"> document.write("Your taxi fare is ₹" + taxiFare(5,2)); </script> </body> </html> pls it would be of great help. Thanx. i, Am developing a webform using PL/SQL. Am using javascript to do some form validation Sample if(a =="") { alert("Please enter the first name"); return false; } else if(b =="") { alert("Please enter the last name"); return false; } else if (y !="Test1") { if (y != "Test2") { if (y != "Test3") { alert("Enter the right text"); return false; } } alert("am wrong outside"); } else if(z =="") { alert("Please fill al the fields"); return false; } it passes till alter("am wrong outside") and executes the procedure but doesnt goes to the last else part. I want it to go the last else part too. Please help. Hello Can i pass php Variable into javascript function like this example. PHP Code: <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("are u sure?") if (answer){ window.location = "user.php?action=statusd&uid=".$row['id'].""; } else{ alert("Canceled") } } //--> </script> This ".$row['id']." will be an user id ... link PHP Code: <a href='#' onclick='confirmation(); return false;'>Go</font></a> Hi Guys, I need a little bit or help with a bit of code I'm writing for a customer. I want to select some data from a database (photo names) and then show pass the information to a JavaScript to display the images on at a time moving onwhen a user click on a 'NEXT' button or back one when the click on a 'BACK' button. Does anyone have any idea on how to do this or is it something that is just no possible? Hi, I hope someone can help me! I have a list of buttons, each with a different id which is taken from the ids of these values from the database. When I click one of the buttons it shows the items that correspond to this id in the database. Therefore, when different buttons are clicked the display changes to match the objects relating to this particular button. When a button is clicked, this shows various other objects which I can then select (using a checkbox). When a checkbox is clicked, a Javascript function is called to change the html text next to the appropriate button. However, I can't get this to work as I need to pass the id of the button, and the html span, to the Javascript in order to change the correct text. Here is my Javascript : Code: function questionnum(checkbox) { if(checkbox.checked) { var qdesNumElement = document.getElementById('<?php echo $q;?>'); var qdesNum = qdesNumElement.innerHTML; qdesNumElement.innerHTML = ++qdesNum; } This code only gets the last button. Please help. Hi, I'm having one javascript function which will return the variable and I need to pass that variable to command button action.Please find the below code and let me know how I can achieve this. <script> function addEntry(entries) { var uploadedEntry = entries[0].entryId; alert("Uploaded Entry Details::::" + uploadedEntry ); } </script> <h:commandButton tabindex="1" image="../img/submit.gif" action="#{portfolioListing.uploadMediaEntry(uploadedEntry)}" Thanks, Anil I want to be able to use on function to check if a field has a value typed in on keyup. But I do not understand how I can get the javascript to pull the value in from the HTML. Here is my JavaScript: Code: <script type="text/javascript"> function validate_now(name) { if (document.upload.(name).value.length == 3) { alert("True"); return true; else { document.upload.(name).style.backgroundColor = "#990000"; return false; } } </script> HTML: Code: <input type="text" name="imageTitle" class="inputField" onkeydown="limitText(this.form.imageTitle,this.form.countdown1,30);" onkeyup="limitText(this.form.imageTitle,this.form.countdown1,30); validate_now('imageTitle')" /> <input readonly type="text" name="countdown1" size="3" value="30" style="background-color:#999999; border:0px; color:#339900; font-family:Calibri; font-weight:bold;"> |