JavaScript - How To Append Two Values As A Url
Hi to all,
Sorry to ak this question it may be easy but i didn't got the solution on net please provide the proper answer. My question is : I am defining hyperlink in struts as <a href= Javascript:formSubmit(<bean:write name="AA" property="aa">','<bean:write name="BB" property="bb">) defining function as function formSubmit(Aa,Bb) { document.forms[0].action="/accesingpage.do?method=create&AA=+Aa" ----> in above statement how to pass the second parameter(i.e Bb)....I tried different ways but giving syntax error. please post the ans as soon as possible Similar TutorialsI'd like to create a basic form where 3 text input fields are named with the following names referrerId, referrerId2 & referrerId3. My goal is once the text fields within the form are populated with the users data, then once the user clicks submit, a new browser window opens up (in parent window preferably), navigating to the following url exactly as shown. Highlighted in red is the dynamic information I'd like appended. Vacation Packages &referrerId=FIRSTNAME&referrerId2=LASTNAME&referrerId3=AGENTNUMBER Any help would be greatly appreciated. Thanks! I am trying to make a lightbox type plugin and I am running into a problem. I hope it is something simple that I am overlooking. Here is my code: jQuery.fn.overlay = function() { $(this).click(function() { $('body').append('<div id="over"></div>'); $('#over').fadeIn(); }); }; It (almost) does what it should. It draws the #over div to the screen just fine. The problem is when I try to access it. I try something like this and get no response: $(function() { $('#over').click(function() { alert('moo'); }); }); Its like the element is not getting the ID assigned to it. Does anyone have any ideas? Thanks in advance. Hi Chaps, I have thumbnail gallery which, when clicked opens up a large version in a div. PHP Code: <p><img id="largeImg" src="images/img1-lg.jpg" alt="Large image" /></p> <p class="thumbs"> <a href="images/img2-lg.jpg" title="Image 2"><img src="images/img2-thumb.jpg" /></a> <a href="images/img3-lg.jpg" title="Image 3"><img src="images/img3-thumb.jpg" /></a> </p> The jQuery Code: Code: $(document).ready(function(){ $(".thumbs a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); $("#largeImg").attr({ src: largePath, alt: largeAlt }); }); }); With a bit of CSS, this is working fine. What I'm trying to do is to: 1. Add attribute to: PHP Code: <p class="thumbs"> <a href="images/img2-lg.jpg" zoom="images/img2-zoom.jpg" title="Image 2"><img src="images/img2-thumb.jpg" /></a> <a href="images/img3-lg.jpg" zoom="images/img3-zoom.jpg" title="Image 3"><img src="images/img3-thumb.jpg" /></a> </p> 2. Add <a id="img_zoom"> to: PHP Code: <p><a id="img_zoom"><img id="largeImg" src="images/img1-lg.jpg" alt="Large image" /></a></p> 3. Add to the jQuery code, to append the "<a>" link, something like: Code: $(document).ready(function(){ $("img_zoom").append('" href="') $(".thumbs a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); var zoomPath = $(this).attr("zoom"); $("#largeImg").attr({ src: largePath, alt: largeAlt }); $("img_zoom").html(zoomPath+" " "); return false; }); }); So when the thumbnail image is clicked, the resulting jQuery output would be something like this: Quote: <a id="img_zoom" href="images/img3-zoom.jpg"> Is this do-able? I've played around with it for ages and can't get it to work. Any hlep would be awesome! edit: I further identified the problem. Hi, I'm new to JavaScript and I'm having problem with appending a div node returned from a function. Here's where it crashed: Code: var div=document.getElementById("dashboard_secondary_cat_list"); var s=get_secondary_cat_node(attributes); alert("b4 appendin:"+s); div.appendChild(s); alert("done appendin"); alert("done appendin"); never gets called because the previous line crashes. alert("b4 appendin:"+s); shows: b4 appendin:[object HTMLDivElement] I have following JS snippet var t = document.createElement ('div'); t.id = "testDiv"; t.innerHTML = "test content"; window.top.document.getElementById ('anotherDiv').appendchild (t); 'anotherDiv' exists in the document; The statement above is not working in IE I'm seeing JS error. but it works in Firefox (i.e t element is appended to anotherDiv). Can any one please let me know how i can resolve this. Hi I am new to javascript programming. Is it possible to append an event handler to a tag dynamically. <input type="button" id="cmdNext" value="Next Page"> i want to be able to programatically loop through the buttons on a page and then add the onClick event. So my finally result will be the following: <input type="button" id="cmdNext" value="Next Page" onClick="CheckValues()"> Since i am new (if possible) can someone provide detail code example so i can break it down and study it before i implement. hello, I'm trying to build a simple function to append and replace an argument in a query string, for example, if my url was like; www.domain.com/page.php?test=123&blah=abc and I want to add on qty=5 like; www.domain.com/page.php?test=123&blah=abc&qty=5 ok, no problem there, however if I now want to update that to qty=6, i get this: http://www.domain.com/page.php?test=...bc&qty=5&qty=6 my code thus far; Code: function AppendURL(){ var AURL = document.getElementById('AddToCartLink'); var numQty = document.getElementById('Qty').value; var TempURL = AURL.href; AURL.href = TempURL + '&Qty=' + numQty; } I have the following code in a website which is the W3C method of loading XML/XSL via Javascript. The code works perfectly except as you can see from the last line of code it appends the fixed div. This is not suitable as I need the site to overwrite the contents of the fixed div (not append). How could I rewrite that last line of code so that the data within the fixed div is rewritten with the contents of resultDocument. innerHTML doesn't work since the content of resultDocument is an XML file. Code: xml=loadXMLDoc("dating_database.xml"); { xsltProcessor=new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml,document); document.getElementById("fixed").appendChild(resultDocument); } I want to append a string "&sid=xyz" to the current page URL if the referring URL comes from site www.xyz.com. I have the following code - var query = location.search.substring(1); if (document.referrer.indexOf(/xyz/) > 0) { query = query + "&sid=xyz"; } However, the string is not being appended. Can anyone see where the problem lies? I have a form with an action url, but I need to alter it on submit. What I need to do is take the value of the text field, escape it, and append it on the end of the action url. Something like this: action url: /search/node appended action url: /search/node/some_escaped_string To do this, I create the function ahead of time and change the submit to a button with onClick. What isn't working is the escape mechanism. If I were to test for "ttt hhh", I'll get "/search/node/ttt hhh", instead of "/search/node/ttt%20hhh" Code: <script type="text/javascript"> function urlAppend() { termsValue = document.getElementById('terms').value; escapedVar = escape(termsValue); appendedUrl = "/search/node/" + escapedVar; location.href = appendedUrl; } </script> <form method="get" action="/search/node"> <input type="text" name="terms" id="terms"></input> <input type="button" value="Search" onClick="urlAppend();"> </form> Can someone tell me what I'm doing wrong? I did something like this: Quote: $('#test').append("<option id='ddm'>added dropdown</option>"); it shows its html in the browser but I can't see it when I view source, is this normal? Thanks. I am attempting to manipulate a long text string with javascript. This text string may have one or more occurrences of a string which starts with a particular string and ends with another string. So, for example, text that starts with 'nam' and ends with 'sit' in this example: Quote: Lorem ipsum dolor sit amet, consectetur adipiscing elit nam aliquam leo sit amet nibh tincidunt ultricies. Nullam nam feugiat velit sit amet dui scelerisque id ornare nulla ultricies. I want to prepend another string before the nam and append another after the sitt, to give me: Quote: Lorem ipsum dolor sit amet, consectetur adipiscing elit before nam aliquam leo sit after amet nibh tincidunt ultricies. Nullam before nam feugiat velit sit after amet dui scelerisque id ornare nulla ultricies. I think the way to do this is via RegExp, but I'm insufficiently familiar with this to know how to write the expression. Can anyone help me out? I have a page with multiple drop down menus for selecting a State then City, then Zip. The State and City both work fine but I can't seem to make the Zip function properly. Page with drop downs: Code: var xmlhttp; function showCity(state) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_cities.php"; url=url+"?q="+state; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } var s=state; function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } var xmlhttp; function showZip(city) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_zips.php"; url=url+"?z="+city; url=url+"&q="+s; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged1; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged1() { if (xmlhttp.readyState==4) { document.getElementById("txtZip").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } <!--********** state drop down *********--> <? $State = mysql_query("SELECT DISTINCT full_state FROM zip_codes ORDER by full_state",$db_link); ?> <select name="state" CLASS="formTextbox" size="1" onChange="showCity(this.value)"> <? while($get = mysql_fetch_array($State)) { ?> <option value="<?=$get['full_state'];?>"><?=$get['full_state'];?></option><? } ?> </select> get_cities.php: Code: <?php $q=$_GET["q"]; include('include/db_con.php'); ?> <? $City = mysql_query("SELECT DISTINCT city FROM zip_codes WHERE full_state = '$q' ORDER BY city",$db_link); ?> <select name="city" CLASS="formTextbox" size="1" onChange="showZip(this.value)"> <? while($get = mysql_fetch_array($City)) { ?> <option value="<?=$get['city'];?>"><?=$get['city'];?></option><? } ?> </select> get_zips.php: Code: <?php $z=$_GET["z"]; $q=$_GET["q"]; include('include/db_con.php'); ?> <? $Zip = mysql_query("SELECT DISTINCT zip FROM zip_codes WHERE city = '$z' AND full_state = '$q' ORDER by zip",$db_link); ?> <select name="zip" CLASS="formTextbox" size="1"> <? while($get = mysql_fetch_array($Zip)) { ?> <option value="<?=$get['zip'];?>"><?=$get['zip'];?></option><? } ?> </select> I have my page set to only show the drop down's when there is a value to select. The Zip drop down shows up at the correct time but is empty. I've tried searching the forum but since I'm still learning js I wasn't able to make use of any on the other multiple drop down examples I came accross. Thanks for any advice you can offer. The code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. The problem is, when I keep issuing the request it keeps appending over and over again Code: if (oSession.uriContains("search?q=")) { var str = oSession.fullUrl; var sAppend = "+test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "search?q=","search?q="+sAppend); } } Can you please give me an example? I'm still new to programming. Thank you Hi gud mng, I have one problem... How to process textbox values/ call textbox values in JS through a Java program. My text box values are dates. I have to process these dates. Like in online banking we select day to know our transactions. After submitting we get results. remember my files are in my directory only. No need of database. My files are look like 20100929, 20100930, 20101001 For epoch_classes.js, epoch_styles.css u can download coding from this link : http://www.javascriptkit.com/script/...ch/index.shtml Code: Code: <html> <table width="900" border="0" cellpadding="10" cellspacing="10" style="padding:0"> <tr><td id="leftcolumn" width="170" align="left" valign="top"> <div style="margin-left:0px;margin-top:0px"><h3 class="left"><span class="left_h2">Select Option</span></h3> <a rel="nofollow" target="_top" href="day_wise.htm" >Day-wise</a><br /> <br /> <a rel="nofollow" target="_top" href="between.htm" >Between Days</a> <link rel="stylesheet" type="text/css" href="epoch_styles.css" /> <script type="text/javascript" src="epoch_classes.js"></script> <script type="text/javascript"> var cal1, cal2; window.onload = function () { cal1= new Epoch('epoch_popup','popup',document.getElementById('popup_container1')); cal2= new Epoch('epoch_popup','popup',document.getElementById('popup_container2')); }; /*............*/ function confirmation(f) { var startdate = f.fromdate.value var enddate = f.todate.value var myday=new Date() var yr=myday.getFullYear() var mn=myday.getMonth()+1 var dt=myday.getDate() var today="" var present, ys, ms, ds, ye,me,de, start, end if(mn < 10) { mn = "0" + mn } if(dt <10) { dt = "0" + dt } today= yr + "/" + mn + "/" + dt present=yr + "/" + mn + "/" +dt if (today < startdate ) { alert (" Start date should not be exceed to-day's date " + present ) startdate.focus() return false } if (today < enddate ) { alert (" End date should not be exceed to-day's date " + present ) enddate.focus() return false } if (today == startdate ) { alert(" You are selected to-days date as Starting day" ); } var answer = confirm("Do you want to continue ?") if (answer) { if( startdate < enddate) alert("Dates between " + startdate + " to " + enddate + " are confirmed" ) else alert("Dates between " + enddate + " to " + startdate + " are confirmed" ) } else { alert("Date not confirmed") window.location="to_date.htm"; } ys= startdate.substring(0,4); ms= startdate.substring(5,7); ds= startdate.substring(8,10); start=ys + "" + ms + "" +ds ye= enddate.substring(0,4); me= enddate.substring(5,7); de= enddate.substring(8,10); end=ye + "" + me + "" +de } /*.......................................................*/ </script> <div style="margin-left:100px;"> <body> <style type="text/css"> #conf { margin-left:115px; } </style> <td align="left" valign="top"> <table width="100" border="0" cellpadding="0" cellspacing="0"> <td style="padding-top:0px"> </table> <h4>From Date</h4> <form name= "formbet" id="placeholder" method="post" action="#" > <input id="popup_container1" type="text" name= "fromdate" maxlength="10" size="20"/> <td align="left" valign="top"> <table width="300" border="0" cellpadding="0" cellspacing="0"> <td style="padding-top:20px"> <h4>To Date</h4> <input id="popup_container2" type="text" name= "todate" maxlength="10" size="20"/> <br /> <br /> <input id="conf" type="button" onclick="confirmation(this.form)" value="Submit"> </form> </body> </html> In my coding, ys, ms, ds represents year starting, month starting, starting day... ye, me, de represents end... start,end gives file names in the format of yyyymmdd now i want to process files from 20100101 to 20100930 means from date is 2010/01/01 and to date is 2010/09/30 if i press submit button the files from 20100101 to 20100930 are processes here ys=2010 ms=01 ds =01 and ye=2010 me=09 de= 30 For this how do i call these textbox values (from date text box and todate) to another program (java) Thanks in advance. I have a bunch of checkboxes like below that the user can check some or all and click the button and see the values of all the selected checkboxes. How can I do that? Code: <script> function alertValues(){ } </script> <input type="checkbox" class ="normal2" value="131971" name="list[]" > <input type="checkbox" class ="normal2" value="131973" name="list[]" > <input type="checkbox" class ="normal2" value="131975" name="list[]" > <input type="checkbox" class ="normal2" value="131977" name="list[]" > <input type="button" onClick="alertValues()" In this case, Let's take Google Search as example: The code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. This code is used in Fiddler(It's a Man-in-the-middle proxy) Code: if (oSession.uriContains("&q=")) // oSession is a Fiddler object session // uriContains() function, checks for case-insensitive string from the URI { var str = oSession.fullUrl; var sAppend = "test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "&q=","&q="+sAppend); } } For those who are confused, It says, If &q= is present in the URI, replace/append &q= with &q=test1+test2+test3 Problem: It appends test1+test2+test3 instantly, when it sees &q= in the URL. Basically, how do I make it wait until I click the submit/search button Thank you. Update: I heard about Onsubmit() event, but not really familiar with it. How do I use it? like, should I go to google source page and edit the form id? Also, Any other methods besides Onsubmit()? Hello. I have a textarea where user can select a text then copy to clipboard (using EditArea script for highlighting) I need append additional information to the selected text so it won't be visible in the textarea, but only appear after copied to clipboard. For example: Code: text line one text line two text line three user selected word "two", hit CTRL+C to copy into clipboard (or used browser's context menu), but in clipboard it should be saved as: "selected word 'two'" What would be the approach? Thank you. |