JavaScript - Print Random A String
Dear all,
I would like to use javascript that prints randomly one string to the string, from an array of predefined string. How do you think I should start thinking that? Alex Similar TutorialsHello everyone. I am completely new to javascript and am basically able to copy/paste code with some minor editing. What I am looking for is a way to have a 5 digit alphanumeric number generated inside a form field to be sent through php(mail). Any help would be greatly appreciated, and any more information I can give, I will gladly do so. I've looked for a solution to this issue, but it seems like a little different scenario than other situations. I made a system for generating friend requests on Facebook. I have a grid that is 6 x 3, for a total of 18 cells. Each cell has a picture in it, and the picture is linked to the Facebook friend request page. My problem is that since each cell is populated at random from the array, I'm getting lots of repeats. For example, some picutures are in 5 cells, and some are in none. I'm trying to figure out how to make it so that once a picture is used once in the grid, it does not get used again in the same grid. I still want every cell filled at random on each page load, I just want to prevent the repeating. Here's my current code: Code: <script type="text/javascript"> var vip_list=new Array( new Array('http://profile.ak.fbcdn.net/v225/1616/88/s1220771654_2158.jpg','http://www.facebook.com/addfriend.php?id=1220771654'), new Array('http://profile.ak.fbcdn.net/v223/1233/29/s904885342_9055.jpg','http://www.facebook.com/addfriend.php?id=904885342'), new Array('http://profile.ak.fbcdn.net/v229/1574/66/s1752031238_626.jpg','http://www.facebook.com/addfriend.php?id=1752031238'), new Array('http://profile.ak.fbcdn.net/v223/768/71/n661155042_7325.jpg','http://www.facebook.com/addfriend.php?id=661155042'), new Array('http://profile.ak.fbcdn.net/v226/732/26/n1827289885_2478.jpg','http://www.facebook.com/addfriend.php?id=1827289885'), new Array('http://profile.ak.fbcdn.net/v229/1631/70/s1425313768_1140.jpg','http://www.facebook.com/addfriend.php?id=1425313768'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1667023416'), new Array('http://profile.ak.fbcdn.net/v225/1146/29/s506485704_9532.jpg','http://www.facebook.com/addfriend.php?id=506485704'), new Array('http://profile.ak.fbcdn.net/profile6/270/32/s692160490_8745.jpg','http://www.facebook.com/addfriend.php?id=692160490'), new Array('http://profile.ak.fbcdn.net/v229/114/83/s1218176198_7375.jpg','http://www.facebook.com/addfriend.php?id=1218176198'), new Array('http://profile.ak.fbcdn.net/v226/946/4/s1470171885_4973.jpg','http://www.facebook.com/addfriend.php?id=1470171885'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1329505888'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1325496968'), new Array('http://profile.ak.fbcdn.net/v223/1546/92/s1536913202_2017.jpg','http://www.facebook.com/addfriend.php?id=1536913202'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1624715433'), new Array('http://profile.ak.fbcdn.net/v228/1282/58/s713998257_3682.jpg','http://www.facebook.com/addfriend.php?id=713998257') ); var chosen_vip=Math.floor(vip_list.length*Math.random()); var chosen_vip1=Math.floor(vip_list.length*Math.random()); var chosen_vip2=Math.floor(vip_list.length*Math.random()); var chosen_vip3=Math.floor(vip_list.length*Math.random()); var chosen_vip4=Math.floor(vip_list.length*Math.random()); var chosen_vip5=Math.floor(vip_list.length*Math.random()); var chosen_vip6=Math.floor(vip_list.length*Math.random()); var chosen_vip7=Math.floor(vip_list.length*Math.random()); var chosen_vip8=Math.floor(vip_list.length*Math.random()); var chosen_vip9=Math.floor(vip_list.length*Math.random()); var chosen_vip10=Math.floor(vip_list.length*Math.random()); var chosen_vip11=Math.floor(vip_list.length*Math.random()); var chosen_vip12=Math.floor(vip_list.length*Math.random()); var chosen_vip13=Math.floor(vip_list.length*Math.random()); var chosen_vip14=Math.floor(vip_list.length*Math.random()); var chosen_vip15=Math.floor(vip_list.length*Math.random()); var chosen_vip16=Math.floor(vip_list.length*Math.random()); var chosen_vip17=Math.floor(vip_list.length*Math.random()); document.write('<center>'); document.write('<a href="',vip_list[chosen_vip][1],'" target="_blank"><img src="',vip_list[chosen_vip][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip1][1],'" target="_blank"><img src="',vip_list[chosen_vip1][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip2][1],'" target="_blank"><img src="',vip_list[chosen_vip2][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip3][1],'" target="_blank"><img src="',vip_list[chosen_vip3][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip4][1],'" target="_blank"><img src="',vip_list[chosen_vip4][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip5][1],'" target="_blank"><img src="',vip_list[chosen_vip5][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip6][1],'" target="_blank"><img src="',vip_list[chosen_vip6][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip7][1],'" target="_blank"><img src="',vip_list[chosen_vip7][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip8][1],'" target="_blank"><img src="',vip_list[chosen_vip8][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip9][1],'" target="_blank"><img src="',vip_list[chosen_vip9][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip10][1],'" target="_blank"><img src="',vip_list[chosen_vip10][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip11][1],'" target="_blank"><img src="',vip_list[chosen_vip11][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip12][1],'" target="_blank"><img src="',vip_list[chosen_vip12][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip13][1],'" target="_blank"><img src="',vip_list[chosen_vip13][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip14][1],'" target="_blank"><img src="',vip_list[chosen_vip14][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip15][1],'" target="_blank"><img src="',vip_list[chosen_vip15][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip16][1],'" target="_blank"><img src="',vip_list[chosen_vip16][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip17][1],'" target="_blank"><img src="',vip_list[chosen_vip17][0],'" height="60" width="60"></a>'); document.write('<br>'); </script> Any suggestions? Thank you! Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response Hi All, I want to show an alert when the page print was sucessfull completed.Indetail if user gives to print then he will able to print or cancel that page.if he print after completion of print i want show an sucessfull alert message.How can i handle this ? Hey, I need to print a PDF from a link, found this Javascript but can't seem to get it working... looks a little bit screwy too... with the script language underscores and stuff and embed tag... i'm looking for more of an a href solution... any thoughts? i also came across the link rel alternate media tag but couldn't get that to work either. Code: <embed src ="<filePath>" width="0" height="0" name="pdfFile"> <script_Language_="javaScript"> function print(){ document.all.pdfFile.print(); } </script> Hello! I have a pretty straight forward question dealing with JQuery/Javascript (I'm pretty new to both, so the syntax is still escaping me). I have a javascript file that holds an array of objects inside of it (addresses to be exact) and I then need to take that array and call it to print into the Title attribute of a <li> after the list has been populated. Below is the Javascript arrray: Code: var banner_data = [ "address1","address2","address3","address4"]; var obj = { one:"address1", two:"address2", three:"address3", four:"address4" } And this is how it is being called in the HTML: Code: $('ul>li').each(function(){ var $this = $(this); // current list item var idx = $this.index(); var thisAddress = banner_data[idx]; $this.attr('title', thisAddress.append[4]) }); any thoughts? I have jQuery 1.7.1 installed, a fully valid html/css and a proper doctype (just to cover our bases haha) I've got a simple script that generates a button that sends to the printer when clicked. But a totally new thing to me is finding a way to update a "printed_unprinted" field in the database for that item. Anyone have experience with this? Right now, I just have: Code: <style type="text/css" media="print"> @page { size:8.5in 11in; margin: 1cm } .printbutton { visibility: hidden; display: none; } </style> <script> document.write("<input type='button' " + "onClick='window.print()' " + "class='printbutton' " + "value='Print This Page'/>"); </script> I assume I could reference a php file? Just something quick like: PHP Code: <?php include("include/conn.php"); $id = mysql_escape_string($_POST['printed']); $query_update = "UPDATE tbl_registration SET reg_hardcopied = '1' WHERE reg_id = '$id'"; $dberror = ""; $ret = mysql_query($query_update); if(!$ret){} else{ //back to referrer } ?> Hi, I want a link on my website where when you press it, it print screens. somthing like, <a href=printscrn();">Print Screen</a> anyone any ideas? Simon I'm working with the squeezebox modal.js implemented with Joomla! for my images in some extra fields. I'm trying to add a print button functionality in order to print the image within the lightbox. Adding the button was fairly easy, I simply copied and pasted this.closeBtn=(new Element("a",{id:"sbox-btn-close",href:"#"})).inject(this.win); and made this.printBtn=(new Element("a",{id:"sbox-btn-print",href:"#"})).inject(this.win); I then made my print button png, went into the modal.css, added this: #sbox-btn-print { position: absolute; width: 30px; height: 30px; right: 10px; top: -15px; background: url(../images/modal/print_btn.png) no-repeat center; border: none; } And boom, print button, however making it work right is certainly not coming along as easy. I tried changing the href to javascript:window.print() but that just prints the contents of the browser, not the image in the box, no bueno. I then tried pushing the button functionality into a separate javascript function, but couldn't even get that far. I'm sure if I tweak it enough I can make it work, but I'm not all that great at programming within javascript. I'm fairly proficient with actionscript, php and css, I just don't know the syntax all involved here. If anyone can point me in the right direction that would be appreciated. Sadly I can't simply switch it out with another lightbox that already has the option to print, as Joomla! K2 Extra Fields doesn't really give you that option. Help! I've searched and searched. It seems the sages, and experienced programmers think var dashes = "------------"; is the easiest way. Certainly there must be some simple (or not as simple) way of printing a line of dashes in javascript without declaring a variable as "----------" (that's just sloppy) I don't mean to be rude but this should be easy. Right? Or must I resort to a loop (probably an integer count) that ends at a declared number like 10 or 20? Thanks, And I really think this thread will come in useful to many others (in future searches) who have had just as hard a time as finding this as I. Thanks again. I have the some text loaded in light box with background faded. i want the print button in the light box so that when user click on that only the contents of light box is printed and printer box opens up. How to do that?? Hey there guys, I'm working with an AJAX request that returns some stuff to print in 2 boxes. All working great, so I decided to make something fluffy, when I click a result in the AJAX request, he filters the clicked result, so you only see that clicked row. When clicked again, the old results will return. All working great. Now, my problem, I wanted a checkbox after every row in the search results and when the user clicks twice on a result to filter it and than goes back to the old results to check the checkboxes again that were checked before filtering that component. I made the functions and it didn't work till I put some alerts in, when the return function got some time to finish printing (like with the user had to click on OK in the alert) it worked. When I deleted the alerts, it didn't work again... I searched on the internet, found a function to wait for an image to load or smth similar and I found some guys that used a function to wait for a specific time (1 sec for example) and that's not what I want. If I use a specific waittime it can still fail if the PC is slow, or whatever, it's just not nice coding. So, is there something I can do so it waits till my AJAX request has been printed? Thanks! 'x. I would like to create a print preview window that will display only the main content of the page that a person would really want to print. I found a script that didn't do that, but that I was able to adapt, somewhat. It doesn't fully work though and I can't get it any better. Here is what I have... <html> <head> <title></title> <script LANGUAGE="JavaScript"> function displayHTML(printContent) { var inf = printContent; win = window.open("print.htm", 'popup', 'toolbar = no, status = no'); win.document.write(inf); } </script> </head> <body> <div id="printarea">Print this stuff.</div> <a href="javascript:void(0);" onclick="displayHTML(printarea.innerHTML)">Print Preview</a> </body> </html> In mozilla it opens the new window but continues to be thinking about something indefinitly. In Safari the new window opens but there is no content. In IE it seems to work fine. I haven't tested NS yet, nor have I tested any of this on a PC. Thanks for any help. Hi everyone! I need a little help with something. I have a page with several links that when clicked open a modal window. The same window for each link, with a form. However inside the form I need to print the id of the link that was clicked. Like so: <a href="#" id="1">Link 1</a> <a href="#" id="2">Link 2</a> <a href="#" id="3">Link 3</a> <form> ....somehow print/echo the id of the link... </form> Is this possible? Does anyone know how to do that? I'd appreciate any help! hey there i was wondering if anyone knows how to get a print option button in a pop up window , i am using html with javascript to create a currency converter i have a button on my main page which opens up a popup window with information taken and totalled from the user input , i would like to be able to offer the option to print this window off . code is function open_win(){ myWindow=window.open('','','width=300,height=300'); myWindow.document.write("<p>Current sterling recieved</p>",sterling_total,"<p>Total commision recieved</p>",commision_total,"<p>Total Money Recieved</p>",running_total); myWindow.focus(); } This should be a simple fix. I have a basic html form with some text input fields and a couple drop down selection lists. Our employees print the form and include it with items they need our shipping department to ship for them. The form uses the following verification script to ensure the required fields have been populated before the screen prints. It works exactly as desired in Safari and Firefox. In Internet Explorer, however, the selections made in the drop down lists are reset to the default values on the printed form. Before you respond with, "don't use Internet Explorer," you have to understand that Internet Explorer is our only corporate approved web browser because it is the only browser supported by some of our other "mission critical" third party web apps and because it can be more rigorously controlled using Group Policies than Safari, Firefox, Chrome, Opera, et al, can. Any advice on how to make the form print without resetting the drop down list selections? Code: <script language="javascript"> function verify() { var themessage = "You must provide the following information"; if (document.shipment.SenderName.value == "") { themessage = themessage + ", Sender Name"; } if (document.shipment.SenderEmail.value == "") { themessage = themessage + ", Sender Email"; } if (document.shipment.Dept.value == "") { themessage = themessage + ", Department"; } if (document.shipment.Contact.value == "") { themessage = themessage + ", Ship To Contact"; } if (document.shipment.Street1.value == "") { themessage = themessage + ", Ship To Street 1"; } if (document.shipment.City.value == "") { themessage = themessage + ", Ship To City / Locale"; } if (document.shipment.country.value == "") { themessage = themessage + ", Ship To Country"; } if (document.shipment.state.value == "") { themessage = themessage + ", Ship To State / Province"; } //alert if fields are empty and cancel form submit if (themessage == "You must provide the following information") { window.print(); return false; } else { alert(themessage); return false; } } </script> Hi, Is there a way to print (sending to printer) the partial contents within the HTML file Ex: Can i print content of div2 only?. <html> <body> <div id='div1'> .... </div> <div id='div2'> .... </div> </body> </html> Can you please let me know your inputs. Thanks.. Hi there, I'm absolute newbie in javascript, so the question may look not worth asking for you. Sorry for that. My situation is like that: I want to make a preview of form data using javascript. After the button "preview" is clicked I start showing div dialog which should contain data entered by users. The problem is that because my div dialog is coded in the same page as form I can get only default values. It means - after making some changes, they are not visible. To get and print the value of input I use this code: Code: <script type="text/javascript"> mytext = document.getElementById('name').value; document.write(mytext); </script> How it would be possible to update the values on "on click" event. Thank you very much for considering this question. |