JavaScript - Passing A Value From Url Using Javascript.
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> Similar TutorialsHello 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 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, 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 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. 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. 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;"> 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 have the following code, where I am inputting a word and on clicking the button , i am setting the value of the text box in div class="twit" which is hidden. now I have to access the value of this hidden text box (name=q) using php.Say I want to print using php .How do I do this ? Code: <html <head> <title></title> <link rel="stylesheet" href="search.css" type="text/css" media="screen" /> <script type = "text/javascript"> function gettweet() { document.getElementById("src").value= document.getElementById("searchbox").value; } </script> </head> <BODY> <form align="center"> <div id="top"> <h3>Search </h3> <input type ="text" name="q1" id = "searchbox"\> <input type ="button" value="ClickMe!" id = "b1" onclick="gettweet();"\> </div> <div id= "twit"> <input type ="text" name="q" id = "src"\> <?php ?> </div> </form> </BODY> </HTML> Hello, 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 Hello! I have a question about a concept I'm working with. I want to create an html page that displays several links to different pages on the site. The user would then be able to drag and drop these links into some sort of list. That part I have figured out. Once they've finished creating their list, they would be able to click on the links in the list. The question I have is this: if they click on a link in the list and go to that page, can their list again be displayed on the new page along with the items they added to it on the previous page? If this is a simple cookie thing, that is awesome. I can't utilize a database or anything server-side for this. HTML and javascript only. Any help would be hugely appreciated, as my programmer is out today.
I need to style a checkbox, so I made it into two images behind a form with hidden inputs. On click the form takes input from the other form into the hidden fields and POSTs it. Then I use PHP to grab that POST and put it back into the original form. Here are some snippets of what I am trying to do: First form input: PHP Code: <input type="text" name="email" id="email1" value="<?php if(isset($_POST['email2'])) { echo $_POST['email2']; } ?>" style="height:25px;width:270px;" /> Second form input: PHP Code: <input type="hidden" name="email2" id="email2" /> Second form submit image button: PHP Code: <input type="image" src="img/Boxchecked.jpg" value="submit" onclick="fname2.value = fname1.value; lname2.value = lname1.value; email2.value = email1.value" width="20" height="20" /> The forms work fantastic on everything but IE, which does not save the field values. How do I fix the onclick event to save them in IE? Help is much appreciated. I'm more of an actionscript person but got roped into an html/javascript job. What I need to do, and it shouldn't be that difficult is this: page1.html - there is a yellow button and a red button - if the user clicks on the yellow button I want to set a cookie with the value "yel" then load the next page - if they click the red button set that cookie with the value "red" page2.html - 'onload' i want to read that cookie and load up the main image to match, something like this maybe?... document.mainimage.src='img/main_' + variable + '.png' so that the path would be for example 'img/main_red.png' Any help please? Preferably javascript only and as simple as possible. If you think this would be easier sending that variable in the URL instead of as a cookie please explain. I'm having a very hard time searching for tutorials that are any good and that do exactly this kind of thing. 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 I have a concatenated list of posts like this: Code: <?php // this generates a list of divs with unique id's as $post_id's $my_posts .= ' <div class="storypost' . $post_id . '"> <a href="mystorypost.php?id=' . $post_id . '>' . $member_name . ' Post</a> <a href="#" onclick="DoAction(' . $mem_id . ', ' . $post_id . ');">Remove?</a> </div> '; ?> And here is the javascript/ajax, which sends the variables to the _removepost.php, in order to run that code, and delete the post from the database... Code: <script> function DoAction(mem_id, post_id) { var r = confirm('Are you sure you want to remove this post?'); if (r == true) { $.ajax({ type: "GET", url: "_removepost.php", data: "mem_id=" + mem_id + "&post_id=" + post_id, }); $(".storypost"+post_id).hide(); return false; } else { return; } } </script> So, the thing actually works (the post gets deleted from the database). But what does not work, is: 1) the div is not getting hidden via the .hide() 2) after I click the onClick link, the page scrolls back to the top of the page... and I have to end up reloading the page to see the change. I believe there is something wrong with where I placed the "return false;" and something wrong with how I call the variable in .hide(). I 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. I few sites said to (in the js file) put the varible in <%= %> these tags but thats not doing any good. Is there some other part needed to this I'm missing. The javascript I'm using is in a file I included in my VS project.
Hi, I have a simple page and a javascript that measure the time the user has spent on a page and I want that variable to pass as a link to another page (php). I'm stuck (rookie) with how to actually pass that on in the link. Here's my code: Code: <?php session_start();?> <html> <head> <script type="text/javascript"> /* This script and many more are available free online at The JavaScript Source :: http://javascript.internet.com Created by: Cody Shaffer :: http://codytheking313.byethost11.com */ var time=1; function timeHere() { time = time + 1; finalTime = time / 10; } </script> </head> <body> <div id="container"> <form id="form1" method="post" action=""> <label>Fill this Data <input type="text" name="1" id="1" /> </label> <p> <label> <input type="submit" name="2" id="2" value="Submit" /> </label> </p> </form> <a href="go/index.html">ads</a> </div> </body> </html> Thanks for the help Hi all, I'm having some trouble with the this... I have a PHP based calendar where the cells will change color depending on the number of clicks.. this all works fine, but is pointless if I can't send the outcome along in an email. I can do this with PHP but first need to get the values into a hidden field. This is what I have: Code: <script type="text/javascript"> function countClicks (obj){ if (!obj.count) { obj.count = 0; } obj.count++; if (obj.count > 4) {obj.count = 1}; if(obj.count == 1){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#66CC33'; obj.parentNode.style.backgroundColor='#66CC33'; document.getElementById("availability").value='Available'; } if (obj.count == 2){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FF0000'; obj.parentNode.style.backgroundColor='#FF0000'; document.getElementById("availability").value='Not Available'; } if (obj.count == 3){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FFCC33'; obj.parentNode.style.backgroundColor='#FFCC33'; document.getElementById("availability").value='Working'; } if (obj.count == 4){ obj.style.color='#000000'; obj.style.backgroundColor='#FFFFFF'; obj.parentNode.style.backgroundColor='#FFFFFF'; document.getElementById("availability").value='Not Set'; } } </script> and... Code: echo "<input type=\"hidden\" name=\"availability\" id=\"availability\" value=\"\">"; All I'm trying to do is populate value with either 'available', 'not available', 'working' or 'not set'... however, it is worth noting that each cell may have a different value, e.g. 1 cell might be working while the other is not available... so i need to pass the values of all the cells. Can anyone help me out here. Many thanks, Greens85 I have a signup form on a site that does a check on submission of fields to see if they populated and error box if not changes focus to missing field and highlights field name in red. I wanted to improve on its effectiveness as it only checks 2 fields atm and I wanted it to check some dynamic fields as well the fields are associative arrays generated via php as follows:- Code: echo "<select name='nfield[$t]'>\n"; for ($i = 0; $i<count($value2); $i++) { echo "<option value=\"".trim($value2[$i])."\">".trim($value2[$i])."</option>\n"; } echo "</select>"; the javascript is as follows:- Code: function checkForm() { //This is the name of the function if (Form1.password.value == "") { alert("Please enter a Password."); Form1.password.focus( ); document.getElementById('password').style.color="red"; return false; } The field is displayed via php as follows:- echo "<tr><td align='center' id='password'>Password:</td><td><input type='password' name='password' size='10'></td></tr>\n"; So i thought ah easy, i will just add the following checking javascript to check each of the associative arrays as they never change Code: if (Form1.nfield[1].value == "") { alert("Please choose an option for option1"); Form1.nfield["1"].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[1]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[2].value == "") { alert("Please choose an option for option2"); Form1.nfield[2].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[2]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[3].value == "") { alert("Please choose an option for option3"); Form1.nfield[3].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[3]').style.color="red"; return false; //This prevents the form from being submitted } but this doesn't work, i think it doesn't recognise the nfield[1] syntax, can a javascript guru point me in the right direction ? I also wanted to enhance the form somewhat as atm it only displays one error popup at a time, so if the user has missed out a few fields they will get an initial popup, try and submit again and then get the second popup for the other missing field. Can my code be modified to show a list of the missing fields and highlight all the titles in red (and if possible change the background colour of the input boxes or border the input fields in red etc)? |