JavaScript - Auto Add To Javascript If Statement If In Mysql Db
Hi,
I have the below code (in a smarty .tpl file), but would like to automate it with data from MySQL DB and PHP So for example if I was to add another gift_id radio box etc.. in MySQL it would add on to the end extending the if statement to make sure a radio box has been picked. if ((form.gift_id[0].checked == false) && (form.gift_id[1].checked == false) && (form.gift_id[2].checked == false)) { ErrorCount++; But the problem is I am not sure how to do this, any ideas? Thanks. ps. sorry if I posted this in the wrong forum, wasn't sure where to put it Similar TutorialsHello, I don't know if this can be done in Javascript, or requires any other language but i was wondering if this would be possible. I would like to embed this Javascript code in to a PHP file and then for it to run automatically upon the PHP file loading: Code: <td class="smallDesc"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </td> The Javascirpt is the Facebook Share button that basically allows users that have Facebook to share the page there currently on in their Facebook status by pressing the button, but if there not logged in it shows the login page, not a problem just continue the script. The current button i which is what i want to load automatically in the PHP file is located here, to test the functionalilty just click "Share" button in blue.. http://watch-movies-online.anyfilman...-Movie-17.html To summarise, i would like the above Javascript code to execute automatically upon pageload of this PHP file.. http://www.watch-movies-online.anyfi...p://google.com. If that could be done, and if this also is possible.. i would like for the "Share" button on the external page that is loaded from the Javascript code above to be clicked automatically so in effect when ever someone visits the PHP page after clicking "Click Here to Watch/Stream 2012 Online For Free" on this page it will automatically load the Facebook Share box, and automatically click the "Share" Button and then close the page if possible, but not required. Please feel free to ask any questions, i'll be happy to answer. Thanks in advance. Best Regards, Jonathan. Hi all, I am newbie to JS. I have the below task. Please advise. I have a result set of a query being displayed on a page. (5000+ rows). I have to provide a search capability, a search box which will enable to enter a position ID number and the entered position ID by the user should be selected from the results in a different color. Can you please help me with the above. Thanks in advance I'm very new to javascript in general, but here's what I'm looking to do: I have a navigation link ("galleries") that 'onclick' displays a sub-menu of other links (the specific galleries). This is on the home page of my site. When a user first views the home page, the sub-menu does not display, until they click "galleries". On other pages of my site, the "galleries" link is one of the options in my navigation. That link takes users back to the home page which is what I want it to do. But what I'm looking for to happen is if the user is directed back to the home page from within another page on my site, I'd like the link on the homepage to automatically display the sublinks under the "gallery" link. This is so that users don't have to click "galleries" twice in order to see the submenu. For example: If a user is on the 'about me' page, in the navigation there is a 'galleries' link. If they click it, it takes them to the home page. They would then have to click on 'galleries' again on the home page in order to display the sub-menu of individual galleries. I want them to show up immediately, but only when directed back to the home page from within my site. I think I do that with an 'if' statement, but I'm not sure of the syntax. I know that's a bit wordy and a little round about but I hope you can understand what I mean. Feel free to ask any questions if I can clarify something for you. Hey helpful folks! I am completely new to Javascript & I have a basic flash gallery that I embedded into my site (HTML & CSS). When viewed in Firefox everything is fine (840px by 427px), but when viewed in IE the gallery changes size & needs to be (887px by 440px) to be viewed correctly. So, I put an Javascript If Then Else statement. Now it targets and changes in the IE browser (width='887' height='440') , but it also changes the Firefox one to 887x440 when it should stay the original 840x427. Please Help!! Thanks! Code: <div id="gallery"> <SCRIPT language="JavaScript"> <!-- var browserName=navigator.appName; if (browserName=="Microsoft Internet <http://www.pageresource.com/jscript/jbrowse.htm#> Explorer") { document.write("<embed src='PhotoSlider.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='840' height='427' ></embed>"); } else { document.write("<embed src='PhotoSlider.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='887' height='440' ></embed>"); } //--> </SCRIPT> </div> Hi, here is my code: Code: <script> $(window).load(function(){ var totalWidth = 0; $("#gallery img").each(function(){ totalWidth += $(this).outerWidth()+20; }); //alert(totalWidth); a = totalWidth+830; $('#content').css({'width' : a+'px'}); }); $('.back a').attr('href','#X'); $('.back a').click(function(){ var halfA = a/'3'; //alert(halfA); $('html, body').animate({scrollLeft: 0}, halfA); }); </script> on the line that reads: a = totalWidth+830; Is it possible to say something like: IF #content 'contains images' THEN a = totalWidth+430; ELSE a = totalWidth+830; OR the other way around: IF #content 'contains <p>' THEN a = totalWidth+830; ELSE a = totalWidth+430; Hey helpful folks! I am completely new to Javascript & I have a basic flash gallery that I embedded into my site (HTML & CSS). When viewed in Firefox everything is fine (840px by 427px), but when viewed in IE the gallery changes size & needs to be (887px by 440px) to be viewed correctly. So, I put an Javascript If Then Else statement. Now it targets and changes in the IE browser (width='887' height='440') , but it also changes the Firefox one to 887x440 when it should stay the original 840x427. Please Help!! Thanks! <div id="gallery"> <SCRIPT language="JavaScript"> <!-- var browserName=navigator.appName; if (browserName=="Microsoft Internet <http://www.pageresource.com/jscript/jbrowse.htm#> Explorer") { document.write("<embed src='PhotoSlider.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='840' height='427' ></embed>"); } else { document.write("<embed src='PhotoSlider.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='887' height='440' ></embed>"); } //--> </SCRIPT> </div> I am looking to validate a drop down list box (Motor_Frame), so when "Num" is selected from it, a value must be entered into the Motor_Frame_num text box. I am trying to use the following code but its not working: <script type="text/javascript"> function validate_form (){ Motor_Frame = document.getElementById('Motor_Frame'); if(Motor_Frame.value.toString() != "Num") else if (Motor_Frame_num.value!="" ) { alert("Please fill in Motor Frame Number with the correct value, a value between 1 and 500") document.forms[0].Motor_Frame_num.focus(); return false; } return true; } </script> I wish to do the AND statement in an IF I would try it but have already frozen myself out trying other things with the server that i do not want to cause anymore problems with them. i.e. Code: if (string1 = "word" AND string2 = "word2") { // do something } Hi, i need a javascript for my website. what i wanna do is that when smone loads my website, the script initiate the left mouse click automatically. that is on page load mouse click is stimulated. dnt know if its possible or not. need help. Thanx in advance hey all- i have been thinking about how i wanted to tackle this for a while now, and it is now "down to the wire"... so in my page i have two nav bars, one for js enabled and one for js disabled... they are styled accordingly (the js disabled is display:inherit; and the js enabled is display:none now i may need to tweak those styles after i get the script working, but that i can toy with after i get this working... anyways- my pages get the navbar inherited from a master page- so my thought was (to prevent loops) make a nav bar that had all js disabled links and a navbar that had all js enabled... then in my code i put in this script Code: <script type="text/javascript"> document.getElementById("Nav_Menu_JS_Content").style.display = "inherit"; document.getElementById("Nav_Menu_Content").style.display = "none"; </script> now i am not amazing with js but i figured this would work... i get an error thrown every time though Quote: Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined now i assume (i am watching in debug) that this is because it is hitting the script before the rest of the page writes... but if i move the script below then the script never fires... ? here are the two nav bar ID's Note: i encapsulated the menus in <div>s and targeted the divs to ensure that there were no conflictions with my asp Code: <div id="Nav_Bar_Menu_Content" class="Nav_Menu"> ......... <div id="Nav_Menu_JS_Content" class="Nav_Menu_JS"> Hey guys. I need a Javascript that clicks on particular co-ordinates on page load. I'll even make do with a script that clicks on a random co-ordinate on page load. Just a simple click has to be made automatically on page load on the page. I tried using and editing this code: Code: <html> <head> <script> window.onload = function(){ document.getElementById("autoid").click(); } </script> </head> <body> <a href="http://google.com" id="autoid">Search Engine</a> </body> </html> but its of no use because I want it to click on another javascript, thats another Code: <script type="text/javascript"> [Script data goes here that takes about 700 x 700 pixels on the screen] </script> I want a click to be made on this script somehow. I can add Code: window.setTimeout('clickit()',5000); function clickit(){ location.href = document.getElementById("autoid"); myself which will delay it so the click occurs after page load but I just want a click to happen on top of that javascript. Any help will be greatly appreciated. Cheers! Hi, I am making a link to the current url and adding ?XXXX to the end of the URL. I have done this like so: Code: <UrlAction Url="javascript:q=(document.location.href);void(open((q)+'?XXXX,'_self','resizable,location,menubar,toolbar,scrollbars,status'))"/> This works perfectly. However I need to add an If statement in this code which does the following: If (there is a ? already in the current url) add &XXXX instead. Can anyone help me add this in? Thanks Hi All I have this basic auto complete JavaScript that works well, but you need to hard code the web page. What I'm trying to do is send the "Autocomplete" variable data to the page using a perl script the working JavaScript code looks like this: var CustomArray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML'); Now the new code is: var CustomArray=new Array(Autocomplete); And the Perl script is sending back the data to the browser looking like this: var Autocomplete = 'an apple','alligator','elephant','pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML' I cant seem to get it to work rite full HTML code is below any help is appreciated. HTML: <html> <head> <script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Autocomplete.js"></script> <script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Common.js"></script> <script language="JavaScript1.2" type="text/javascript" src="http://www.ComicInvasion.com/cgi-bin/Autocomplete.pl"></script> <script> var CustomArray=new Array(Autocomplete); </script> </head> <body> <input type='text' style='font-family:verdana;width:300px;font-size:12px' id='ACMP' value=''/> <script> var obj = actb(document.getElementById('ACOMP'),CustomArray); </script> </body> </html> I am using this script to automatically set the current date on a form... However, when I post the form, it is actually putting the Day +1 into the database (the year and month are correct). So for example if I set the date to June 8, 2011 on the form, it will post into the db as 2011-06-09. I am not sure whats going on... Also, if the form has a missing input field (and the form reloads), the date resets back to the current date, instead of retaining the php-printed date values. In the head, I have: Code: <script> var monthtext=['January','February','March','April','May','June','July','August','September','October','November','December']; function populatedropdown(dayfield, monthfield, yearfield){ var today=new Date() var dayfield=document.getElementById(dayfield) var monthfield=document.getElementById(monthfield) var yearfield=document.getElementById(yearfield) for (var d=1; d<32; d++) dayfield.options[d]=new Option(d, d+1) dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day for (var m=0; m<12; m++) monthfield.options[m]=new Option(monthtext[m], monthtext[m]) monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month var thisyear=today.getFullYear() for (var y=0; y<4; y++){ yearfield.options[y]=new Option(thisyear, thisyear) thisyear-=1 } yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year } </script> In the form I have: Code: <script type="text/javascript"> //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select) window.onload=function(){ populatedropdown("daydropdown", "monthdropdown", "yeardropdown") } </script> <tr> <td> <select name="Month" id="monthdropdown"> <option value="<?php print "$Month"; ?>"><?php print "$Month"; ?></option> </select> <select name="Day" id="daydropdown"> <option value="<?php print "$Day"; ?>"><?php print "$Day"; ?></option> </select> <select name="Year" id="yeardropdown"> <option value="<?php print "$Year"; ?>"><?php print "$Year"; ?></option> </select> </td> </tr> My html form code is <html> <head> <script type="text/javascript" src="2.js"></script> </head> <body> <h1 id="remain"></h1> <form action="3.php" method="post" id="form1" name="form1"> <input type="text" name="id"> <input type="submit" name="submit" value="submit"> </form> </body> </html> I need to submit the form after coundown.Here is my countdown script file window.onload=counter; function counter() { var seconds = 5; countDown(); function countDown() { document.getElementById("remain").innerHTML=seconds; if(seconds>0) { seconds=seconds - 1; setTimeout(countDown,1000); } if(seconds == 0) { document.form1.submit(); } } } Countdown is working but form does not submit after countdown.Please help me regarding this.Thanks in advance Hello All, I have a form where the number of input fields (lets call them B through N) is determined by the length of a php array. Above those input fields is another field (lets call this field input A) that I would like to be auto populated based on what the user enters in fields B through N. Here is my code. The first table (with all of the "totals" fields) holds all of the input fields that I would like to auto update. These fields should auto update so that every input in EACH of the "fy" fields in the second table is added together. Example: every input in the id="fy_{$fy.fy}_high_impact_cost" field should be added together as the user enters them, and the id="totals_high_impact_cost" field should be auto updated with that total. Code: <form method="post" name="submit" action="new_item.php" accept-charset='UTF-8'> <table border="box" width="100%"> <tr> <td align="center">$<input id="totals_high_impact_cost" size="3" name="totals_high_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_most_likely_impact_cost" size="3" name="totals_most_likely_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_low_impact_cost" size="3" name="totals_low_impact_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_actual_expense" size="3" name="totals_actual_expense" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_high_mitigation_cost" size="3" name="totals_high_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_most_likely_mitigation_cost" size="3" name="totals_most_likely_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_low_mitigation_cost" size="3" name="totals_low_mitigation_cost" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_cost_in_scope" size="3" name="totals_cost_in_scope" maxlength="20" style="text-align: right" />M</td> <td align="center">$<input id="totals_unfunded_threat" size="3" name="totals_unfunded_threat" maxlength="20" style="text-align: right" />M</td> </tr> </table> {foreach value=fy from=$php_array} <table> <tr> <td align="center">$<input id="fy_{$fy.fy}_high_impact_cost" size="3" name="fy_{$fy.fy}_high_impact_cost" maxlength="20" style="text-align: right" value="{$fy.high_impact_cost}" onchange="update_totals_high_impact_cost()" />M</td> <td align="center">$<input id="fy_{$fy.fy}_most_likely_impact_cost" size="3" name="fy_{$fy.fy}_most_likely_impact_cost" maxlength="20" style="text-align: right" value="{$fy.most_likely_impact_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_low_impact_cost" size="3" name="fy_{$fy.fy}_low_impact_cost" maxlength="20" style="text-align: right" value="{$fy.low_impact_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_actual_expense" size="3" name="fy_{$fy.fy}_actual_expense" maxlength="20" style="text-align: right" value="{$fy.actual_expense}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_high_mitigation_cost" size="3" name="fy_{$fy.fy}_high_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.high_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_most_likely_mitigation_cost" size="3" name="fy_{$fy.fy}_most_likely_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.most_likely_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_low_mitigation_cost" size="3" name="fy_{$fy.fy}_low_mitigation_cost" maxlength="20" style="text-align: right" value="{$fy.low_mitigation_cost}" />M</td> <td align="center">$<input id="fy_{$fy.fy}_cost_in_scope" size="3" name="fy_{$fy.fy}_cost_in_scope" maxlength="20" style="text-align: right" value="{$fy.cost_in_scope}" />M</td> </tr> </table> {/foreach} </form> Please email me at alexhall12315@yahoo.com if you would like more explanation. Thanks in advance for any help!!! =) Hi, I'm pretty new in Javascript. I searched alot but didn't find any answer to my problem I have. What I want to do: - I have a cell A1 - I want the script to make a new cell B1 - After that I want the script to make a new cell C1 - After that I want the script to make a new cell D1 - After that I wa .... etc .... till I got 20 cells in total. This has to go automatic so not by use of a client sided button. I also need every cell to get his own IDnumber like A1 ID=1, B1 ID=2, C1 ID=3, etc to communicate with database and mysql. But maybe I have to use php for that. Thanx for any help! Best regards, Thoaren Hey I was wondering, I have a box with tabs at the bottom. As you click the tabs, different stories appear in the box. However, I have the box in a fixed length. So if stories are longer, then they disappear beneath the visible line of the box. When I had it auto-adjusting though, the box would change based on the story I was clicking on. It gets weird. Is there a way to have the box auto-adjust based on the largest amount of text and have it stay that height regardless on what story you pick? I hope this makes sense. Thanks! KZ Hello. I open a new forum thread as adviced by jmrker. Old forum thread related to this topic: http://www.codingforums.com/showthre...8#post12243889 Here is my code, based on the latest Philip M's work : Code: <html> <head> <script type = "text/javascript"> var cday; var timeInSecs; var ticker; function getSeconds() { var now = new Date(); var nowtime= now.getTime(); // time now in milliseconds var countdowntime = new Date(now.getFullYear(),now.getMonth(),now.getDate(),20,0,0); // 16 hrs = 4 pm // countdowntime - change time hh,mm,ss to whatever time required, e.g. 7,50,0 (0750) var dy = 5 ; // Friday (day 5) - change for other days 0-6 var atime = countdowntime.getTime(); var diff = parseInt((atime - nowtime)/1000); // positive if date is in future if (diff >0) { cday = dy - now.getDay(); } else { cday = dy - now.getDay() -1; } if (cday < 0) { cday += 7; } // aleady passed countdown time, so go for next week if (diff <= 0) { diff += (86400 * 7) } startTimer (diff); } function startTimer(secs) { timeInSecs = parseInt(secs); ticker = setInterval("tick()",1000); tick(); // to start counter display right away } function tick() { var secs = timeInSecs; if (secs>0) { timeInSecs--; } else { clearInterval(ticker); // stop counting at zero getSeconds(); // and start all over again! } var days = Math.floor(secs/86400); secs %= 86400; var hours= Math.floor(secs/3600); secs %= 3600; var mins = Math.floor(secs/60); secs %= 60; var result = days +':'; result += ((hours < 10 ) ? "0":"" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0":"" ) + secs + ""; document.getElementById("countdown").innerHTML = result; } </script> </head> <body onload = "getSeconds()" style="background-color: #ffffff;"> <br><br> <div id="CountDownLogo" style="background-color: #ffffff; width:300px; height: 180px; background-image:url(ScreenShot002.png) "> <span id="title" style="font-family: arial; font-size: 20; font-weight: bold; color: #ffffff; position: relative; top:27px; left:60px; z-index:1;">Weekend Cup 2012</span> <br><br> <span id="countdown" style="font-family: arial; font-size: 25; font-weight: bold; color: #3b3b3b; position: relative; top:34px; left:127px; z-index:1;"> </span> <br><br> </div> </body> </html> My event takes place at 8pm on fridays. To see if this script works in all conditions, I change my system date and time (to see if the script displays the good remaining duration). TESTS: Friday - So I set my system date on friday but at different times. When I do that, everything seems to work fine. - If I chose an earlier time (11am for example), it's fine too. - If I chose 7:59:45 pm (and wait a few seconds) I can see the countdown resetting and displaying 6 days 23 hours 59 min 59 sec. So it's fine too. Saturday - But if I chose saturday 00:00:01 am it doesn't work. It displays 0:19:59:59 (as if the event occured the same day, saturday). - And if I chose saturday 7:59:45 pm, the counter resets and displays 6 days 23 hours 59 min 59 sec.. Which is also wrong because it would mean that the even occurs on saturdays 8pm. Sunday - Same for sunday (the same errors like saturdays) Btw, could it be possible to display on the HTML page, all variable values ? This could help me understand how the script is done. (I am a poor coder). Thank you very much. Hello, I came across a very odd browser behavior when trying to modify a css class using javascript and at the same time having a base html statement in my html file. Without the base html statement, all browsers work fine and I can change the css class definition using javascript easily. With a base html statement, only FireFox still works while Internet Explorer and Google Chrome dont work anymore. If there is a cross-domain issue, while one browser does work and the others dont? An example of what I'm talking about, with the base statement: http://freebsdcluster.org/~casaschi/...mple-base.html Without the base statement: http://freebsdcluster.org/~casaschi/...le-nobase.html Any idea how to tweak the code in the case with the base html statement in order for the javascript to work with all browser (modifying the class definition) ??? Keep in mind, I dont want a suggestion of another way to change the color, this is only an example. I want to be able to manipulare css classes with javascript when a base html statement is in my html code. This is essentially the code: Code: <!-- --> <base href='http://www.google.com'> <style id='myStyle' type='text/css'> .myStyle { color: red; } </style> <script type="text/javascript"> var lastColor = 'red'; function toggleColor() { lastColor = lastColor == 'red' ? 'green' : 'red'; myObject = document.getElementById('myStyle'); if (myObject.sheet) { myObject.sheet.cssRules[0].style.color = lastColor; } // Mozilla style if (myObject.styleSheet) { myObject.styleSheet.rules[0].style.color = lastColor; } // IE style } </script> <a href="javascript: toggleColor();"><span class=myStyle>click here to toggle color</span></a> Thanks in advance... |