JavaScript - How To Combine Smtp With Your Own Code?
I have these two codes which both involve sockets. I can't figure out how to combine the smtp code into my first code. If you look at the first code where it prints out "you are at picture A" it is here were i want to be able to send an email. I am quite puzzled as how to combine the two codes to make it work. Any help would be greatly appreciated.
First Code: Code: import java.io.*; import java.net.*; import java.util.Scanner; import java.io.File; public class Combo2 { public static void main(String[] args) throws IOException { Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; File yourFile = new File("outs.txt"); yourFile.delete(); try { kkSocket = new Socket("192.168.33.39", 12000); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: Adam."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: Adam."); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; String fromUser; while ((fromServer = in.readLine()) != null) { if (fromServer.equals("Bye.")) break; try{ // Create file FileWriter fstream = new FileWriter("outs.txt", true); BufferedWriter outs = new BufferedWriter(fstream); outs.write( fromServer); outs.newLine(); //Close the output stream outs.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } FileReader fin = new FileReader("outs.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { Double Tag = (src.nextDouble()); Double x = (src.nextDouble()); Double z = (src.nextDouble()); Double y = (src.nextDouble()); if ((x<=19.92) && (y<=6.1543) && (y>=4.22)) { System.out.println("You are at Picture A"); } else if ((x<=19.92) && (y<=3) && (y>=1)) { System.out.println("You are at Picture B"); } else { System.out.println("Nope"); } } } out.close(); in.close(); stdIn.close(); kkSocket.close(); } } SMTP code: Code: import java.io.*; import java.net.Socket; public class Emailer { public static void main(String[] args) throws Exception { String results = send("mailhost.computing.dcu.ie", 25, "adam.keaney2@mail.dcu.ie", "adam.keaney2@mail.dcu.ie", "Test Email", "<b>You got mail!</b>"); System.out.println(results); } /* Sends an email. * @return The full SMTP conversation as a string. */ public static String send( String host, int port, String to, String from, String subject, String message) throws Exception { // Save the SMTP conversation into this buffer (for debugging) StringBuffer buffer = new StringBuffer(); try { // Connect to the SMTP server running on the local machine. Socket smtpSocket = new Socket(host, port); // send commands TO the server with this DataOutputStream output = new DataOutputStream(smtpSocket.getOutputStream()); // recieve responses FROM the server with this BufferedReader input = new BufferedReader( new InputStreamReader( new DataInputStream(smtpSocket.getInputStream()))); try { // Read the server's hello message read(input, buffer); // Say hello to the server send(output, "HELO localhost.localdomain\r\n", buffer); read(input, buffer); // Who is sending the email send(output, "MAIL FROM: " + from + "\r\n", buffer); read(input, buffer); // Where the mail is going send(output, "RCPT to: " + to + "\r\n", buffer); read(input, buffer); // Start the message send(output, "DATA\r\n", buffer); read(input, buffer); // Set the subject send(output, "Subject: " + subject + "\r\n", buffer); // If we detect HTML in the message, set the content type so it displays // properly in the recipient's email client. if (message.indexOf("<") == -1) { send(output, "Content-type: text/plain; charset=\"us-ascii\"\r\n", buffer); } else { send(output, "Content-type: text/html; charset=\"us-ascii\"\r\n", buffer); } // Send the message send(output, message, buffer); // Finish the message send(output, "\r\n.\r\n", buffer); read(input, buffer); // Close the socket smtpSocket.close(); } catch (IOException e) { System.out.println("Cannot send email as an error occurred."); } } catch (Exception e) { System.out.println("Host unknown"); } return buffer.toString(); } /** * Sends a message to the server using the DataOutputStream's writeBytes() method. * Saves what was sent to the buffer so we can record the conversation. */ private static void send(DataOutputStream output, String data, StringBuffer buffer) throws IOException { output.writeBytes(data); buffer.append(data); } /** * Reads a line from the server and adds it onto the conversation buffer. */ private static void read(BufferedReader br, StringBuffer buffer) throws IOException { int c; while ((c = br.read()) != -1) { buffer.append((char) c); if (c == '\n') { break; } } } } Similar TutorialsI have this java function that will show the div based on whatever u select. Each div is a different set of form fields. My problem is if you change 1/2 and go to the other selection, it'll submit BOTH. not just the one you currently switched to. So if i can modify this fucntion to add the ability to either clear the divs not being used (will a clear'd div still submit data?), or reset.fields (would that do it?). I am new to javascript, thanks in advance guys Here is my code for the change div's: Quote: <script type="text/javascript"> $(document).ready(function(){ $('#3_form').hide(); $('#4_form').hide(); $('#axd_form').hide(); $('#ht_form').hide(); $("#thechoices").change(function(){ if(this.value == 'all') {$("#boxes").children().show();} else {$("#" + this.value).show().siblings().hide();} }); $("#thechoices").change(); }); </script> And here is the code to clear the div: Quote: <script type="text/javascript"> function clearDiv() { document.getElementById("4_form").innerHTML=""; } </script> So if #3_form --> clear all other div's. (4_form, axd_form, and ht_form) I just need to clear the div that isnt currently selected - idk what the best practice is for that. It must not allow other fields in other div's to be submitted in the form. So basically just clear the fields. would clearing a div do that? thanks! Is there a way to check for A , else check for B? The code in Red is what I need to put together. [This is an event calendar. problem is it double prints the event dates.Original problem is here. http://www.codingforums.com/showthread.php?t=186671] Thanks for looking! Code: /* Function List: yearly(calendarDay) Creates the yearly calendar, highlighting the date specified in the calendarDay parameter. writeMonthCell(calendarDay, currentTime) Writes the yearly table cell containing a monthly calendar. writeMonth(calendarDay, currentTime) Creates the calendar table for the month specified in the calendarDay parameter. The currentTime parameter stores the time value of the current date. writeMonthTitle(calendarDay) Writes the month name in the monthly table writeDayNames() Writes the weekday title rows in the calendar table daysInMonth(calendarDay) Returns the number of days in the month from calendarDay writeMonthDays(calendarDay, currentTime) Writes the daily rows in the monthly table, highlighting the date specified in the currentTime parameter. writeDay(weekDay, dayCount, calendarDay, currentTime) Write the opening and close table row tags and the table cell tag for an individual day in the calendar. */ function yearly(calDate) { if (calDate == null) calendarDay=new Date(); else calendarDay = new Date(calDate); var currentTime = calendarDay.getTime(); var thisYear = calendarDay.getFullYear(); document.write("<table id='yearly_table'>"); document.write("<tr><th id='yearly_title' colspan='4'>"+thisYear+"</th></tr>"); var semMonth=calendarDay.getMonth(); var monthNum; if (semMonth <6) { monthNum = -1 } else { monthNum = 5; } for (var i=1; i<=2; i++) { document.write("<tr>"); for (var j=1; j<=3; j++) { monthNum++; calendarDay.setDate(1); calendarDay.setMonth(monthNum); writeMonthCell(calendarDay, currentTime); } document.write("</tr>"); } document.write("</table>"); } function writeMonthCell(calendarDay, currentTime) { document.write("<td class='yearly_months'>"); writeMonth(calendarDay, currentTime); document.write("</td>"); } function writeMonth(calendarDay, currentTime) { document.write("<table class='monthly_table'>"); writeMonthTitle(calendarDay); writeDayNames() writeMonthDays(calendarDay, currentTime); document.write("</table>"); } function writeMonthTitle(calendarDay) { var monthName = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var thisMonth=calendarDay.getMonth(); document.write("<tr>"); document.write("<th class='monthly_title' colspan='7'>"); document.write(monthName[thisMonth]); document.write("</th>"); document.write("</tr>"); } function writeDayNames() { var dayName = new Array("S", "M", "T", "W", "R", "F", "S"); document.write("<tr>"); for (var i=0;i<dayName.length;i++) { document.write("<th class='monthly_weekdays'>"+dayName[i]+"</th>"); } document.write("</tr>"); } function daysInMonth(calendarDay) { var thisYear = calendarDay.getFullYear(); var thisMonth = calendarDay.getMonth(); var dayCount = new Array(31,28,31,30,31,30,31,31,30,31,30,31); if ((thisYear % 4 == 0)&&((thisYear % 100 !=0) || (thisYear % 400 == 0))) { dayCount[1] = 29; } return dayCount[thisMonth]; } function writeMonthDays(calendarDay, currentTime) { var weekDay = calendarDay.getDay(); document.write("<tr>"); for (var i=0; i < weekDay; i++) { document.write("<td></td>"); } var totalDays = daysInMonth(calendarDay); for (var dayCount=1; dayCount<=totalDays; dayCount++) { calendarDay.setDate(dayCount); weekDay = calendarDay.getDay(); writeDay(weekDay, dayCount, calendarDay, currentTime); } document.write("</tr>"); } function writeDay(weekDay, dayCount, calendarDay, currentTime) { //my var lines .ID and events. var ID = ( calendarDay.getFullYear() * 10000 + calendarDay.getMonth() * 100 + 100 + calendarDay.getDate() ); // This is where you put in the appointments. follow pattern [YYYYMMDD,"start time - End time : message"], var events = [ [20100130,"4pm - 10 pm : Beer fest"], [20100320,"10am - 6 pm : the next fest"], [20100425,"8am - 2 pm : the other fest"], ]; //end of events // end of my var declaration if (weekDay == 0) document.write("<tr>"); // this code is to write my buggy events. IDs are fine.events are the bug //my for line for(var sep = 0; sep < events.length; sep++) { //end of my for line // writes the events to the date if (events[sep][0] == ID) { document.write("<td id="+ID+" class='monthly_dates'><div class='eventday' title='" + events[sep][1] + "'>"+dayCount+"</div></td>"); } } // my } for, for var sep //end of my buggy lines //normal day writing if (calendarDay.getTime() == currentTime) { document.write("<td class='monthly_dates' id='today'>"+dayCount+"</td>"); } else { document.write("<td id="+ID+" class='monthly_dates'>"+dayCount+"</td>"); } if (weekDay == 6) document.write("</tr>"); } Hi, well i have heard alot about combining script but never did that as i always had doubts about the proper method of doing it, as these days following standards matters alot for SEO. I want to combine scripts together into one file, lets take an example i will provide 3 scripts 1- Code: <script type='text/javascript'> $(document).ready(function () { // find the elements to be eased and hook the hover event $('div.jimgMenu ul li a').hover(function() { // if the element is currently being animated if ($(this).is(':animated')) { $(this).addClass("active").stop().animate({width: "310px"}, {duration: 450, easing: "easeOutQuad", complete: "callback"}); } else { // ease in quickly $(this).addClass("active").stop().animate({width: "310px"}, {duration: 400, easing: "easeOutQuad", complete: "callback"}); } }, function () { // on hovering out, ease the element out if ($(this).is(':animated')) { $(this).removeClass("active").stop().animate({width: "83.7px"}, {duration: 400, easing: "easeInOutQuad", complete: "callback"}) } else { // ease out slowly $(this).removeClass("active").stop(':animated').animate({width: "83.7px"}, {duration: 450, easing: "easeInOutQuad", complete: "callback"}); } }); }); </script> 2- Code: <script type="text/javascript"> (function($) { $.fn.sorted = function(customOptions) { var options = { reversed: false, by: function(a) { return a.text(); } }; $.extend(options, customOptions); $data = $(this); arr = $data.get(); arr.sort(function(a, b) { var valA = options.by($(a)); var valB = options.by($(b)); if (options.reversed) { return (valA < valB) ? 1 : (valA > valB) ? -1 : 0; } else { return (valA < valB) ? -1 : (valA > valB) ? 1 : 0; } }); return $(arr); }; })(jQuery); $(function() { var read_button = function(class_names) { var r = { selected: false, type: 0 }; for (var i=0; i < class_names.length; i++) { if (class_names[i].indexOf('selected-') == 0) { r.selected = true; } if (class_names[i].indexOf('segment-') == 0) { r.segment = class_names[i].split('-')[1]; } }; return r; }; var determine_sort = function($buttons) { var $selected = $buttons.parent().filter('[class*="selected-"]'); return $selected.find('a').attr('data-value'); }; var determine_kind = function($buttons) { var $selected = $buttons.parent().filter('[class*="selected-"]'); return $selected.find('a').attr('data-value'); }; var $preferences = { duration: 800, easing: 'easeInOutQuad', adjustHeight: 'dynamic' }; var $list = $('#data'); var $data = $list.clone(); var $controls = $('ul#gamecategories ul'); $controls.each(function(i) { var $control = $(this); var $buttons = $control.find('a'); $buttons.bind('click', function(e) { var $button = $(this); var $button_container = $button.parent(); var button_properties = read_button($button_container.attr('class').split(' ')); var selected = button_properties.selected; var button_segment = button_properties.segment; if (!selected) { $buttons.parent().removeClass('selected-0').removeClass('selected-1').removeClass('selected-2'); $button_container.addClass('selected-' + button_segment); var sorting_type = determine_sort($controls.eq(1).find('a')); var sorting_kind = determine_kind($controls.eq(0).find('a')); if (sorting_kind == 'all') { var $filtered_data = $data.find('li'); } else { var $filtered_data = $data.find('li.' + sorting_kind); } if (sorting_type == 'size') { var $sorted_data = $filtered_data.sorted({ by: function(v) { return parseFloat($(v).find('span').text()); } }); } else { var $sorted_data = $filtered_data.sorted({ by: function(v) { return $(v).find('strong').text().toLowerCase(); } }); } $list.quicksand($sorted_data, $preferences, function () { $(this).tooltip (); } ); } e.preventDefault(); }); }); var high_performance = true; var $performance_container = $('#performance-toggle'); var $original_html = $performance_container.html(); $performance_container.find('a').live('click', function(e) { if (high_performance) { $preferences.useScaling = false; $performance_container.html('CSS3 scaling turned off. Try the demo again. <a href="#toggle">Reverse</a>.'); high_performance = false; } else { $preferences.useScaling = true; $performance_container.html($original_html); high_performance = true; } e.preventDefault(); }); }); </script> 3- Code: <script type='text/javascript'> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-15016456-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> I want to add them to one file and then yes i am going to make it external. Here i have a few questions: 1- Can any type of scripts be added together? 2- Is there a general rule of doing this combination of scripts (e-g remove the <script> tags from start and end of all then give spaces between each and you are done). 3- Should one use JS compressors? if yes, what are advantages and disadvantages of doing so? I asked a few question together as i don't want to spam this forum ^_^ anyway these all question are related to my topic My site loads too many javascript files and it takes much time to load page. I would like to reduce the number of http requests and combine all javascript files into one file. What is the best way for it? Will it work if I just copy whole code from all files and paste into one or anything else is needed? Thanks I am new to using Javascript. Can someone help me combine these two codes? I can't get it to work. [code] body {background-color: #FFFFee;} .c { position: absolute; font-size: 1px; background:red; height: 2px; width: 2px; } .d { position: absolute; font-size: 1px; background:blue; height: 2px; width: 2px; } </style> </head> <body> <script language="javascript"> var i,y,x,y1; for (i=1; i<600; i++) { y=150-100*Math.sin(i/50); y1=150-100*Math.cos(i/50); x=i+50; document.write("<span class='c' style='left:"+x+";top:"+y+";'></span>"); document.write("<span class='d' style='left:"+x+";top:"+y1+";'></span>"); } [code] with this one. [code] .moveimage { position:absolute; left:20; top:50; z-index:2; } </style> <script language="JavaScript"> var fishLeft = 20; var imgWidth = 106; function moveFish() { var elem = document.getElementById("myDiv"); fishLeft+=4; if(fishLeft > document.body.clientWidth + (imgWidth / 2)) fishLeft = imgWidth / 2; elem.style.left = fishLeft; window.status= fishLeft ; setTimeout("moveFish()", 100); } </script> <title></title> </head> <body> <br> <div id="myDiv" class="moveImage"><img src="fish1.gif"></div> <br><br><br><br><br><br><br><br><br> <input type="button" value="Move Fish" onClick="moveFish()" ID="Button1" NAME="Button1"> [code] Hi! What I really mean is how can you combine the effects from two plugins. Subject line only gives you so much to work with. I'm trying to use the query.corner.js plugin and the gradient (jquery.gradient.js & jquery.dimensions.js) plugins to get a rounded container that has a gradient applied to it. I've tried a few different things like putting a container withing a container and applying one plugin to one and the other to the remainder. No luck! |= Here's the code I'm playing with: 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" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> JQuery combo plugins </title> <style type="text/css"> div.main { background:#0000FF;height:400px;width:400px;margin:auto;font-size:2em;text-align:center;} .main p {padding:20px;} </style> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/jquery.corner.js"></script> <script type="text/javascript" src="/js/jquery.gradient.js"></script> <script type="text/javascript" src="/js/jquery.dimensions.js"></script> <script type="text/javascript"> $(function(){ $('div.main').corner("20px"); }); </script> <script type="text/javascript"> $(function() { $('.gmain').gradient({ from: '0000FF', to: 'FFFFFF', direction: 'horizontal', position: 'verticle', }); }); </script> </head> <body> <div class="main"> <div class="gmain"> <p>Hi There!</p> </div> </div> </body> </html> I attached the js plugins and just changed the extension from js to txt so I could attach them. I did NOT attach the jquery script since I figure that is pretty common. Corner -> jquery.corner.txt Dimension -> jquery.dimensions .txt Gradient -> jquery.gradient.txt Thanks for your help! Hi! I'm trying to cmbine 4 .js file into one unique file. I'm getting some troubles because jquery.singlePageNav.js seems not to work. Can someone help me to combine these 4 files? Thank you js.rar Note: major noobage here I'm sure... but can't seem to figure this out... How do I make these three functions into one script? Much love if you can help! Code: <script type="text/javascript"> setTimeout('yourFunction();', 2500); function yourFunction(){ document.getElementById('hide').style.display='block'; } </script> <script type="text/javascript"> setTimeout('yourFunction2();', 8000); function yourFunction2(){ document.getElementById('hide').style.position='fixed'; } </script> <script type="text/javascript"> setTimeout('yourFunction3();', 8500); function yourFunction3(){ document.getElementById('hide').style.margin='0 -310px'; } </script> <script type="text/javascript"> setTimeout('yourFunction4();', 15500); function yourFunction4(){ document.getElementById('hide').style.margin='0 610px'; } </script> Hi, I have a form where dob is generated using 3 select boxes, 1 for day, month and year. My output needs to be in the form dob=dd-mm-yyyy rather than day=dd, month=mm and year=yyyy. It has been suggested that i do the following: "On submit button click, use JS to create a hidden input (Q5) in the form and assign its value, then disable the day, month, and year fields so they are not submitted." Does anyone know how to do this? Can anyone tell me how I can combine multiple sheets into one?
I am try to make a form that appears to be multi page. I am trying to use a button to hide one div and display another at the same time my script is head Code: <script language=javascript type='text/javascript'> function hidediv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){//if they are 'see' divs if (document.getElementById) // DOM3 = IE5, NS6 divs[i].style.visibility="hidden";// show/hide else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'hidden'; else // IE 4 document.all.hideShow.divs[i].visibility = 'hidden'; } } } function showdiv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){ if (document.getElementById) divs[i].style.visibility="visible"; else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'visible'; else // IE 4 document.all.hideShow.divs[i].visibility = 'visible'; } } } </script> body Code: <form name="PublicOrderPage" action="save_client_information.php" onsubmit="return validateForm()" method="post"> <div id="div1" style="width:600px; height: auto;background: yellow;"> <table width="600" border="0"> <tr> <legend><h3 style="padding-left:172.5px;">Required Client Information</h3></legend> </tr> <tr> <td style="padding-left:25px;"><b>Name:</b></td> <td><input type="text" name="client_name" id="client_name" value="<?php echo $_POST['client_name']; ?>" /></td> <td style="padding-left:25px;"><b>Home Phone:</b></td> <td><input type="text" name="client_home_phone" id="client_home_phone" value="<?php echo $_POST['client_home_phone']; ?>" /></td> </tr> </table> <br/> <table width="270" border="0"> <tr> <td style="padding-left: 180px;"><b>Email:</b></td> <td><input type="text" name="client_email" id="client_email" value="<?php echo $_POST['client_email']; ?>" /></td> </tr> </table> <br/> <table> <tr> <td style="padding-left:280px;"><input name="save_client_info" type="button" value="Next" onclick="hidediv('1');shwodiv('2');" > </td> </tr> </table> </div> <div id="div2" style="width:600px; height: auto;background: yellow; "> <table width="600" border="0"> <tr> <legend><h3 style="padding-left:172.5px;">Required Site Information</h3></legend> </tr> <tr> <td style="padding-left:25px;"><b>Site Street:</b></td> <td><input type="text" name="site_street" id="site_street" value="<?php echo $_POST['site_street']; ?>" /></td> <td style="padding-left:25px;"><b>Site City:</b></td> <td><input type="text" name="site_city" id="site_city" value="<?php echo $_POST['site_city']; ?>" /></td> </tr> </table> <br/> <legend><h3>Inspection Type</h3></legend> <table width="270" border="0"> <table width="602" border="0"> <tr> <td width="252"><input type="checkbox" name="cb_full_home" id="cb_full_home" <?php if ($_POST['cb_full_home']) echo 'checked="checked"'; ?> /> Full Home</td> <td width="150"><input type="checkbox" name="cb_4_point" id="cb_4_point" <?php if ($_POST['cb_4_point']) echo 'checked="checked"'; ?> /> 4 Point</td> </tr> <tr> <td ><input type="checkbox" name="cb_condominium" id="cb_condominium" <?php if ($_POST['cb_condominium']) echo 'checked="checked"'; ?> /> Condominium</td> <td ><input type="checkbox" name="cb_wind_mit" id="cb_wind_mit" <?php if ($_POST['cb_wind_mit']) echo 'checked="checked"'; ?> /> Wind Mit</td> </tr> <tr> <td ><input type="checkbox" name="cb_roof_cert" id="cb_roof_cert" <?php if ($_POST['cb_roof_cert']) echo 'checked="checked"'; ?> /> Roof Cert</td> <td ><input type="checkbox" name="cb_drywall" id="cb_drywall" <?php if ($_POST['cb_drywall']) echo 'checked="checked"'; ?> /> Drywall</td> </tr> <tr> <td><input type="checkbox" name="cb_reinspect" id="cb_reinspect" <?php if ($_POST['cb_reinspect']) echo 'checked="checked"'; ?> /> Re-Inspect</td> <td><input type="checkbox" name="cb_followup" id="cb_followup" <?php if ($_POST['cb_followup']) echo 'checked="checked"'; ?> /> Follow-Up</td> </table> <img src="CaptchaSecurityImages.php" /> Security Code: <input id="security_code" name="security_code" type="text" /> <br /> <input name="save_client_info" type="submit" value="Save" /> </div> </form> When the next button is used I would Like to Hide Div1 And Display Div2 so that it looks as if it is a new page. Any help would be greatly appreciated. Code: function materiaalkost(selectVeld, nr) { // Stuur informatie terug if (document.getElementsByName('inkoop[]')[nr].value == '') { document.getElementsByName('materiaalkost[]')[nr].value = (document.getElementsByName('gewicht_stk[]')[nr].value * (document.getElementsByName('inkoop_b').value / 1000)).toFixed( 2 ) } else { document.getElementsByName('materiaalkost[]')[nr].value = (document.getElementsByName('gewicht_stk[]')[nr].value * (document.getElementsByName('inkoop[]')[nr].value / 1000)).toFixed( 2 ) } } With the above code I'm trying to manipulate the 'materiaalkost[]' field. This field is in an loop. When the field 'inkoop[]' is not used the script should use the 'inkoop_b' field, this field is not in the for loop. For some reason even when 'inkoop[]' is not used this field is used but it should use the field 'inkoop_b'. The problem is that document.getElementsByName('inkoop_std').value is not in the loop like all other elements. How can I use an element that is outside the for loop in the loop? I'm working in iWeb (I had to say that first). I need to create (using JAVASCRIPT) a text box with a button. When the button is clicked, the contents of the box are added to the URL (the url is in the code, probably a variable, for this example it is mydomain.wordpress.com/) and the url produced loads. For example, if the text "Hello" was printed in the text box once the button is clicked the page mydomain.wordpress.com/Hello is loaded.
Right now this javascript shopping cart works to 1. charge shipping based on the item, 2. the destination country, 3. it combines shipping for a quantity over 1 of the SAME item. Each item has 2 different possible shipping charges. I am trying to get the javascript to check the shopping cart to see what item in the cart has the highest possible shipping charge, charge that amount to that item, and charge the lowest possible shipping charge on all other items in the cart. If item A is purchased alone shipping is $5.00. If purchased with item B, which costs $10.00 to ship alone, the $10.00 is charged for item B and only $3.00 for item A. Because item B had the higher shipping charge at a quantity of one. I have tried adding various things like me.items[current], item.shipping, me.shipping, this.shipping, shipping_Cost, and other things next to the second && in the part of the script that shows the country. I have also tried adding && if (me.whatever) and && if (item.whatever) and similar things at the beginning of the script next to if (this.country). I have found the parts of the script that pertain to cart items and to updating the shopping cart. Now I am stuck. The javascript is in 2 parts. One part goes in the item page, which I will post first. The second part goes in an external javascript file which I will post at the bottom. In between there is the part that shows the shopping cart. It isn't part of the javascript. Code: <script type="text/javascript" src="simpleCart.js"></script> <script type="text/javascript"> <!-- simpleCart.checkoutTo = PayPal; simpleCart.email = "my Paypal email address"; simpleCart.cartHeaders = ["Name" , "Price" , "Quantity" , "remove" ]; CartItem.prototype.shipping=function(){ // we are using a 'country' field to calculate the shipping, // so we first make sure the item has a country if(this.country){ if( this.country == 'United States' && this.quantity == '1'){ return this.quantity*5.00; } else if( this.country == 'United States' && this.quantity >= '2') { return this.quantity*3.00; } else if( this.country == 'Belgium' && this.quantity == '1') { return this.quantity*12.00; } else if( this.country == 'Belgium' && this.quantity >= '2') { return this.quantity*9.00; else { return this.quantity*0.00; } } else { // use a default of $0.00 per item if there is no 'country' field return this.quantity*0.00; } } // --></script> Code: <div style="display:block;"></div> <div>SHOPPING CART</div> <div class="cartHeaders"></div><br><br><br> <div class="simpleCart_items"></div> <div id="totals"> Item Total: <span class="simpleCart_total"></span><br>Shipping Total: <span class="simpleCart_shippingCost"></span><br>Tax: <span class="simpleCart_taxCost"></span><br>Final Total: <span class="simpleCart_finalTotal"></span> </div> <br><br><br><br> <br><br> <a href="javascript:;" class="simpleCart_empty">Empty Shopping Cart</a><br><br> <a href="javascript:;" class="simpleCart_checkout">Checkout Through Paypal</a> </div></div> separate javascript file is here http://simplecartjs.com/documentation.html Hi, When designing a web page, you may come across a situation where you want to combine content from multiple websites in a single window. Could the "iframe" tag makes this possible? If so, as it will separate your page design into several sections and display a different website in each one? Your answers are much appreciated. Thank you for watching me. Stickers I am trying to combine shipping across different items in a javascript shopping cart. I can comine shipping based on how many items are in the cart, and characteristics of the item being added. But not both. I need the script to combine shipping based on how many items are in the cart, as well as the item name of the item being added to the cart. I assume I need to check the cart quantity in 1 function, then have it call 1 of 2 other functions based on how many items are in the cart. The 2nd function would charge the shipping based on the item name. I don't know if the code is wrong, and where I should put the 2 additional functions I am adding. It isn't working though. I am adding 2 ways I have tried below. Code: me.shipping = function(){ switch(me.quantity){ case '0': return 0; break; case '1': return oneItemInCart(); break; default: otherNumber; return moreThanOneItemInCart(); break; } function oneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return 4.39 else if(item.name.match = "Glitter") return 5.00 else return quantity*0.00; } } function moreThanOneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return item.quantity*3.00-3.00+4.39 if(item.name.match = "Glitter") return item.quantity*4.00-4.00+5.00 else return quantity*0.00; } } Code: me.shipping = function(){ if( parseInt(me.quantity,10)===0 ) return 0; else if( parseInt(me.quantity,10)===1) return oneItemInCart(); else if( parseInt(me.quantity,10) > 1) return moreThanOneItemInCart(); else return quantity*0.00; function oneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return 4.39 else if(item.name.match = "Glitter") return 5.00 else return quantity*0.00; } } function moreThanOneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return item.quantity*3.00-3.00+4.39 if(item.name.match = "Glitter") return item.quantity*4.00-4.00+5.00 else return quantity*0.00; } } Here is the original document - the part I edited is the me.shipping part http://simplecartjs.com/ This post will contain a few guidelines for what you can do to get better help from us. Let's start with the obvious ones: - Use regular language. A spelling mistake or two isn't anything I'd complain about, but 1337-speak, all-lower-case-with-no-punctuation or huge amounts of run-in text in a single paragraph doesn't make it easier for us to help you. - Be verbose. We can't look in our crystal bowl and see the problem you have, so describe it in as much detail as possible. - Cut-and-paste the problem code. Don't retype it into the post, do a cut-and-paste of the actual production code. It's hard to debug code if we can't see it, and this way you make sure any spelling errors or such are caught and no new ones are introduced. - Post code within code tags, like this [code]your code here[/code]. This will display like so: Code: alert("This is some JavaScript code!") - Please, post the relevant code. If the code is large and complex, give us a link so we can see it in action, and just post snippets of it on the boards. - If the code is on an intranet or otherwise is not openly accessible, put it somewhere where we can access it. - Tell us any error messages from the JavaScript console in Firefox or Opera. (If you haven't tested it in those browsers, please do!) - If the code has both HTML/XML and JavaScript components, please show us both and not just part of it. - If the code has frames, iframes, objects, embeds, popups, XMLHttpRequest or similar components, tell us if you are trying it locally or from a server, and if the code is on the same or different servers. - We don't want to see the server side code in the form of PHP, PERL, ASP, JSP, ColdFusion or any other server side format. Show us the same code you send the browser. That is, show us the generated code, after the server has done it's thing. Generally, this is the code you see on a view-source in the browser, and specifically NOT the .php or .asp (or whatever) source code. I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files F:\Textbooks.html F:\eBooks.txt F:\FirstBook.txt F:\SecondBook.txt F:\ThirdBook.txt textbooks.html is my DHTML app eBooks.txt is the Library file with a listing of all of my eBooks. Inside of eBooks.txt is the following data: ----------------- FirstBook.txt, SecondBook.txt, ThirdBook.txt, ----------------- FirstBook.txt to ThirdBook.txt are my actual ebooks. The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error: ---------------------------------- Error: unterminated string literal Source File: file:///F:/Textbooks.html Line: 1, Column: 10 Source Code: LoadEbook(' ---------------------------------- So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data. I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem. did i forget something silly? LOL i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers. here is my HTML code: <html> <head> <script language="JavaScript"> var eBookLibrary = "eBooks.txt"; var SystemPath = "f:" + String.fromCharCode(92) function Init() { // Initialize the eBook reader document.getElementById("EbookCanvas").style.visibility = "hidden"; document.getElementById("EbookToolbar").style.visibility = "visible"; document.getElementById("FileManager").style.visibility = "visible"; // Load the List of eBooks in the Library LoadBookList(); } function UpdateEbookList() { // Update the Library of Ebooks alert("Updating eBook Library"); // Go back to the File Manager, and Reload the List of Ebooks LoadBookList(); } function LoadBookList() { // This will load the list of books that are available var EbookList = LoadFromDisk(SystemPath + eBookLibrary); var EbookListArray = EbookList.split(","); for(var x = 0; x < EbookListArray.length -1; x++) { // Strip the Filename Extension off of the eBook File Name // The Name of the Book is always the first Index in the Array var BookName = EbookListArray[x].split("."); // Remove the weird whitespace - it screws things up...i think... BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, ""); var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>"; } // For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense // So just delete that from the HTMLdata string, because it's just ugly - LOL HTMLdata = HTMLdata.replace("undefined", ""); HTMLdata = HTMLdata.replace("", " "); // Write the HTML data to the DIV document.getElementById("FileManager").innerHTML = HTMLdata; } function LoadEbook(EbookName) { // Hide the File Manager and Show the Ebook Canvas document.getElementById("FileManager").style.visibility = "hidden"; document.getElementById("EbookCanvas").style.visibility = "visible"; document.getElementById("EbookToolbar").style.visibility = "visible"; // Load the Ebook content into the Ebook Reader Pannel var EbookContent = LoadFromDisk(SystemPath + EbookName); document.getElementById("EbookCanvas").innerHTML = EbookContent; } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } </script> </head> <body onLoad="Init();"> <div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;"> The eBook Library's List of Books will be listed here. Click on one to open it in the eBook Reader </div> <br> <div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;"> </div> <br> <div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;"> <input type="button" value="Open" OnClick="Init();"> <input type="button" value="Update" OnClick="UpdateEbookList();"> <input type="button" value="Exit" OnClick="MainMenu();"> </div> </body> </html> Hi all, I hope someone can advise whether such a script exists for what am wanting to do. From time to time, I need to send password information or login details and password information to some users. At the moment, am doing it via email with a subject named FYI and the body of the email basically just contain the login and the password or in some case, just the password. What am wanting to know is whether I can put these information into a HTML file which contains an obfuscated Javascript with a button that a user will click that will prompt for his login information and then will display the password. In its simplest form, I guess I am looking for a Javascript that will obfuscate a HTML file that contains the password. Anyway, hopefully someone understand what am looking for. I found some website that offers such service as obfuscating a HTML file but am hoping it can be done via a Javascript so it is at least "portable" and I do not have to be online. Any advice will be much appreciated. Thanks in advance. Hi guys.. I really need a bit of help.. is anyone looking at this good with JS? I have a php form validation script but i think its a bit slow and would rather a JS script instead... here is what i have in php.. PHP Code: <?php if(isset($_POST['submit'])) { $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $mobile = $_POST['mobile']; $comments = $_POST['comments']; $errors = array(); function display_errors($error) { echo "<p class=\"formMessage\">"; echo $error[0]; echo "</p>"; } function validateNames($names) { return(strlen($names) < 3); } function validateEmail($strValue) { $strPattern = '/([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})/sim'; return(preg_match($strPattern,$strValue)); } function validateMobile($strValue) { $strPattern = '/^\d{10}$/'; return(preg_match($strPattern,$strValue)); } function validateComments($comments) { return(strlen($comments) < 10); } if(validateNames($firstName)) { $errors[] = 'Please Enter Your First Name'; } if(validateNames($lastName)) { $errors[] = 'Please Enter Your Second Name'; } if(!validateEmail($email)) { $errors[] = 'Please Enter Your Correct Email'; } if(!validateMobile($mobile)) { $errors[] = 'Please Enter Your Correct Mobile Number'; } if(validateComments($comments)) { $errors[] = 'Please Enter A Comment More Than 10 Characters'; } if(empty($errors)) { $to = "info@eventpromotion.ie"; $subject = "Event Promotion Enquiry!"; $body = "First Name: " . $_POST['firstName'] . "\nLast Name: " . $_POST['lastName'] . "\nEmail: " . $_POST['email'] . "\nMobile: " . $_POST['mobile'] . "\nMessage: " . $_POST['comments']; $headers = "From: ". $firstName ." ". $lastName . " <" . $email . ">\r\n"; if (mail($to, $subject, $body, $headers)) { echo("<p class=\"formMessage\">Thanks for submitting your enquiry.</p>"); } else { echo("<p class=\"formMessage\">Message delivery failed.</p>"); } } else { //echo "error"; display_errors($errors); } } ?> <form id="form" method="post" action="index.php#quickContact"> <p> <label>First Name</label><br /> <input type="text" name="firstName" value="<?php if(isset($firstName)){echo $firstName;} ?>" /> </p> <p> <label>Last Name</label><br /> <input type="text" name="lastName" value="<?php if(isset($lastName)){echo $lastName;} ?>" /> </p> <p> <label>Email:</label><br /> <input type="text" name="email" value="<?php if(isset($email)){echo $email;} ?>" /> </p> <p> <label>Mobile:</label><br /> <input type="text" name="mobile" value="<?php if(isset($mobile)){echo $mobile;} ?>" /> </p> <p> <label>Comments:</label> <br /> <textarea name="comments" cols="30" rows="3" ><?php if(isset($comments)){echo $comments;} ?></textarea> </p> <p> <input class="send" type="image" src="images/submit2.gif" name="submit" value="Submit" /></p> </form> does anyone know how to transfer this to JS so that it will be easy to understand.. Im not good with JS at all |