JavaScript - Javascript Syntax ...help Plz
I have a webpage that has "classes" that are dynamically populated. if a class is empty, or not populated, can I use JavaScript to hide the "class"? If so How?
Sorry for such a noob question. Thanks in advance for any help Similar TutorialsI badly need a Javascript syntax checker for my Javascript. Any suggestionss will be gratefully received. Frank Hi, Im currently building my first website, I'm trying to use a JQuery Slider effect for a top banner, however I seem to be getting a syntax error after the javascript. Any ideas? Ive attached a screenshot of the code Thanks Simon I am studying the javascript. I got following codes from json2.js but do not understand syntax of them. if (!this.JSON) { this.JSON = {}; } (function () { ... }()); For 2nd part, why there is () outsider function? and why these is () after function? Thanks a lot. Hi all, can anyone tell me why the connection string for the jscript doesn't work but vbscript does? I'm using IE7 only. ------------------------------------ Code Start ----------------------------- <html> <head> <title></title> <script language="vbscript"> Sub GetVBscriptData() Set oADOCon = CreateObject("ADODB.Connection") Set oRecSet = Createobject("ADODB.recordset") oADOCon.ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" oADOCon.Open oRecSet.Open "SELECT * FROM Customers", oADOCon sList = "" Do Until oRecSet.EOF sList = sList & oRecSet("NewFirstName") & vbCrLf oRecSet.MoveNext Loop MsgBox sList End Sub </script> <script language="javascript"> function GetJScriptData() { var oADOCon = new ActiveXObject("ADODB.Connection"); var oRecSet = new ActiveXObject("ADODB.Recordset"); var ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" ; oADOCon.Open(ConnectionString); oRecSet.Open("SELECT * FROM Customers",oADOCon); var sList = ""; while (!oRecSet.EOF){ sList = sList + oRecSet("NewFirstName"); oRecSet.MoveNext(); } alert(sList); } </script> </head> <body> <input type="button" onclick="GetVBscriptData()" value=" Get some data via vbscript"> <input type="button" onclick="GetJScriptData()" value=" Get some data via javascript"> </body> </html> ------------------------------------- Code End ------------------------------ The error I receive is: Message: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. Line: 26 (opening the javascript connection) I can only presume it's the syntax of the connection string. Any ideas how to alter the string to get it connecting? Thanks in advance, t-racer I'm receiving the following errors: line 6 Expected an element name[xml] line 17 the input ended before all started tags were ended. last tag started was 'script'[xml] Code: <script type="text/javascript"> var camp = xfa.resolveNodes("camp[*]"); var total = 0; for (var i=0; i <= camp.length-1; i++) { if (camp.item(i).isNull) { total = total; } else { total = total + 30; } } this.rawValue = total; </script> I've got next to zero experience with javascript so not even sure what I should be looking to fix...any help is appreciated, if I need to answer something I missed, just let me know. favorite I'd like to modify a form on www.formsite.com (form builder app): username: testuser password: password I would like to use the nicedit.com's inline content editor's js to transform my textarea's into a richtext area. At present the nicedit editor works well in creating the richtextarea. However, the KEY point is that I would like formsite's form to pipe in the the created html and render it with the html component of formsite. Currently, the pipe function in formsite will only put out the html syntax in it's html module. action seen he http://fs8.formsite.com/testform/form1/index.html So this would be: 1. checking out my form on formsite.com 2. the script from nicedit.com is already installed in an html component. 3. changing or telling me the scripts/tags/or whatever for formsite form using formsites form builder (which allows some html/script editing). 4. changed so as to render the rich text entered on page 1 in page 2 instead of the html syntax. Any other solutions using formsite and any other richtextarea solutions would be great too! I'm a PHP guy and haven't used jQuery much. I have a script I found in a book and I am trying to get working and am having trouble. It's a drop down list. I am using it in place of an HTML select box, so I want to pass the value selected from the list along with the form in a hidden field. My question is how do I extract the value out of the JS function and get it into the hidden field? Code: $(document).ready(function() { createDropDown(); $(".dropdown dt a").click(function(event) { event.preventDefault(); var dropID = $(this).closest("dl").attr("id"); $("#" + dropID).find("ul").toggle(); }); $(document).bind('click', function(e) { var $clicked = $(e.target); if (! $clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide(); }); $(".dropdown dd ul a").click(function() { var dl = $(this).closest("dl"); var dropID = dl.attr("id"); var text = $(this).html(); var source = dl.prev(); $("#" + dropID + " dt a").html(text); $("#" + dropID + " dd ul").hide(); source.val($(this).find("span.value").html()) }); }); function createDropDown() { var selects = $("select.dropdown_value"); var idCounter = 1; selects.each(function() { var dropID = "dropdown_" + idCounter; var source = $(this); var selected = source.find("option[selected]"); var options = $("option", source); source.after('<dl id="' + dropID + '" class="dropdown"></dl>'); $("#" + dropID).append('<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>'); $("#" + dropID).append('<dd><ul></ul></dd>'); options.each(function() { $("#" + dropID + " dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>'); }); idCounter++; }); } I'm learning to program, and am having some issues with the syntax of my "if" statement. I've looked online but still can't get it to work. Here's the code: Code: function checks(){ if(document.myform.checkbox.checked == true){ window.open("http://www.espn.html", "mywindow"); } else{ document.write("hello world"); } } //document.write("hello world");} I know the function is being called properly because when I hit "submit" on the form the document.write("hello world"); statement prints on a new page. But for some reason when I call the function and that part is commented out, nothing happens. Any idea what I'm doing wrong? I tried looking online but can't figure anything out. Thanks in advance. Hi all, I have some card/images and would like to have the first one displayed.Which i can do. Then when I mouse click on the card/image it goes to another image for say 2 secs, then with out clicking goes back to the orignal card. I have played with the syntax for ages and also looked on the net and cannot get it right. This is what I have so far. Code: <html> <head> <script> var back = new Image(); back.src = "back.gif";// preloads the image. var ace = new Image(); ace.src = "0.gif"; //Preload the Image var two = new Image(); two.src = "1.gif";// preloads the image. var three = new Image(); three.src = "2.gif";// preloads the image. var four = new Image(); four.src = "3.gif";// preloads the image. var five = new Image(); five.src = "4.gif";// preloads the image. </script> </head> <body> <img name="img0"> <img name="img1"> // what is this for? <script> document.images['img0'].src = back.src;//displays image /*How do I have one card diplayed then mouseclick on that one card and another card will display for 2 secs then the card will go back to original card. */ </script> </body> </html> Any ideas ? Thanks heaps Shayne Can someone explain to me the differences between the following code snippets? Mainly i don't understand the purpose of using prototype and not sure if there is a functional difference between the syntax of declaring functions. Code: var myObj = function () { this._myInt = 1; } myObj.prototype = { myNewFunction: function() { this._myInt = 2; } } VERSUS Code: var myObj = function () { this._myInt = 1; function myNewFunction(){ this._myInt = 2; } } i get this error when ever i try to process the form: There was a SyntaxError: Unexpected token < error due to an parsererror condition. Javacsipt/jquery: $(document).ready(function(){ $("#slide").click(function(){ $("#inner-wrapper").slideToggle(); }); $('form #response').hide(); $('#submit').click(function(e){ e.preventDefault(); var valid = ''; var required = ' is required'; var name = $('form #name').val(); var email = $('form #email').val(); var fname = $('form #fname').val(); var femail = $('form #femail').val(); var message = $('form #message').val(); var honeypot = $('form #honeypot').val(); var humancheck = $('form #humancheck').val(); //Error checking if (name == '' || name.length <=2) { valid = '<p>Your name' + required + '</p>'; } if (!email.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/)) { valid += '<p>Your email' + required + '</p>'; } if (fname == '' || fname.length <=2) { valid += '<p>Your friend\'s name' + required + '</p>'; } if (!femail.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/)) { valid += '<p>Your friend\'s email' + required + '</p>'; } if (message == '' || message.length <=5) { valid += '<p>A message' + required + '</p>'; } if (honeypot != 'http://') { valid += '<p><center>Spambots are not allowed.</center></p>'; } if (humancheck != '') { valid += '<p><center>A human user' + required + '</center></p>'; } if (valid != '') { $('form #response').removeClass().addClass('error') .html('<strong>Please correct the errors below.</strong>' + valid).fadeIn('2000'); }else { $('form #response').removeClass().addClass('processing').html('<center>Working...</center>').fadeIn('2000'); var formData = $('form').serialize(); submitForm(formData); } }); }); function submitForm(formData) { $.ajax({ type: 'POST', url: 'emailfriend.php', data: formData, dataType: 'json', cache: false, timeout: 7000, success: function(data) { $('form #response').removeClass().addClass((data.error === true) ? 'error' : 'success') .html(data.msg).fadeIn('fast'); if ($('form #response').hasClass('success')) { setTimeout("$('form #response').fadeOut('slow')", 5000); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { $('form #response').removeClass().addClass('error') .html('<p>There was a <strong>' + errorThrown + '</strong> error due to an <strong>' + textStatus + '</strong> condition.</p>').fadeIn('fast'); }, complete: function(XMLHttpRequest, status) { $('form')[0].reset(); } }); }; php file PHP Code: <?php error_reporting(E_ALL ^ E_NOTICE); sleep(3); $name = stripslashes($_POST[name]); $email = stripslashes($_POST[email]); $fname = stripslashes($_POST[fname]); $femail = stripslashes($_POST[femail]); $message = stripslashes($_POST[message]); $honeypot = $_POST[honeypot]; $humancheck = $_POST[humancheck]; if ($honeypot == 'http://' && empty($humancheck)) { $error_msg = ''; $reg_exp = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"; if (!preg_match($reg_exp, $email)) { $error_msg .= "<p>A valid email is required</p>"; } if (!preg_match($reg_exp, $femail)) { $error_msg .= "<p>A valid email is required</p>"; } if (empty($name)) { $error_msg .= "<p/>Please provide your name</p>"; } if (empty($fname)) { $error_msg .= "<p/>Please provide your name</p>"; } if (empty($message)) { $error_msg .= "<p>A message is required.</p>"; } if (!empty($error_msg)) { $return['error'] = true; $return['msg'] = "<h3>Oops! Looks like you missed a few fields.</h3>".$error_msg; echo json_encode($return); exit(); }else { $return['error'] = false; $ref=@$HTTP_REFERER; /////Message at the top of the page showing the url//// $header_message = "Hi $fname \n Your friend $name requested you to visit this page at \n $ref \n"; /// Body message prepared with the message entered by the user //// $body_message =$header_message."\n".$message."\n"; // IP address of visitor is added to message, you can remove it if not required.// $body_message .="\n Sent from http://www.separatethescams.com"; //// Mail posting part starts here ///////// $headers=""; //$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers; // Un comment the above line to send mail in html format $headers4=$email; // Change this to change from address $headers.="Reply-to: $headers4\n"; $headers .= "From: $headers4\n"; $headers .= "Errors-to: $headers4\n"; $subject="$name visit this site!"; mail($femail,$subject,$body_message,$headers); $return['msg'] = " <b><p><center>Thanks for spreading the word! :) " . "<font color='red'>" .$name . "</font>" . " </p>" . "</b>" . "</center>"; echo json_encode($return); } }else { $return['error'] = true; $return['msg'] = "<h3><center>0ops there was a problem submitting the data. Please try again!</center></h3>"; echo json_encode($return); } ?> html file <html> <head> <link rel="stylesheet" href="ajaxform/form.css" type="text/css" media="screen"/> </head> <body> <div id="wrapper"> <h3 id="slide">Email This Page To a Friend</h3> <hr></hr> <div id="inner-wrapper"> <form id="my_form" action="ajaxform/emailfriend.php" method="post"> <div id="response"><!--This will hold error message and response from server. --></div> <div class="inputs"> <p> <label>Name   ; </label> <input name="name" type="text" placeholder="Your Name" class="required" id="name" size="30" /> </p> </div> <div class="inputs"> <p> <label>Email &nbs p; </label> <input name="email" type="text" placeholder="Your Email" class="required" id="email" size="30" /> </p> </div> <div class="inputs"> <p> <label>Friend's Name </label> <input name="fname" type="text" placeholder="Friend's Name" class="required" id="fname" size="30" /> </p> </div> <div class="inputs"> <p> <label>Friend's Email </label> <input name="femail" type="text" placeholder="Friend's Email" class="required" id="femail" size="30" /> </p> </div> <div class="inputs"> <p> <label id="msg">Message </label> <textarea name="message" cols="24" rows="5"type="text" placeholder="Message To Friend" class="required" id="message"></textarea> </p> </div> <div class="button"> <input name="submit" type="submit" id="submit" value="EMAIL PAGE" /> </div> <div class="inputs"> <input type="hidden" name="honeypot" id="honeypot" value="http://" /> <input type="hidden" name="humancheck" id="humancheck" class="clear" value="" /> </div> </form> </div> <!-- inner-wrapper end --> </div> <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="ajaxform/ajax_submit.js"></script> </body> </html> I just found this forum! I'm glad because I wanted to ask some javascript questions before. There was a question at work before at why one would use the following: if (a=='1') ... or if ('1'==a) ... Is there any kind of advantage of using one of the other? Thanks for any response! On this page http://jimpix.co.uk/ecards/262-no-words.html I get this Javascript error in IE6: Code: Line: 5 Character: 1 Code: 0 Error Message: Syntax error URL: http://jimpix.co.uk/ecards/262-no-words.html I'm using the DebugBar add in for IE (http://www.debugbar.com/) The error message in DebugBar is this: http://jimpix.co.uk/junk/error.png And the view-source of the page is he http://jimpix.co.uk/junk/source-code.png I don't get the error in Firefox 3 or IE7. I can't work out how to fix it. Any advice would be much appreciated. Thanks! Code: out += (out ? rogueArray[14] : rogueArray[13]) + arrayItem + ((vanWilder[arrayItem] !== null) ? = + encodeURIComponent(vanWilder[arrayItem]) : rogueArray[13]); There is supposedly a syntax error here on the line up until [arrayItem in Dreamweaver. Any help? I keep getting myself into trouble because I tend to use my Java reference when coding Javascript, and of course Javascript doesn't support all Java functions. I've just discovered that apparently Javascript doesn't support the trim() function. But curiously, if I code it as: mystring.trim() then Firefox will handle it without any errors. (I haven't actually checked to see if whitespace is removed from around the string.) But when I code it like this: trim(mystring) then firefox gives an error. I've also found a couple of situations where I've made syntax errors, and Firefox gives no error message. This makes debugging tricky, since the only resource I have available is Firefox's Error Console. Safari has no error reporting whatsoever, AFAIK. MSIE seems to find some errors that Firefox misses, but I don't have MSIE on my main computer, so it's a nuisance to use. As a hobbyist, I have no budget to buy Javascript development tools. Is there something free available that does a better job of finding errors? Can someone point where i'm going wrong? I want to evaluate the values of 'miles' to be >=0 and 'putime' to between 0 and 24 only. Code: <script type = "text/javascript"> function TaxiFare() { // calculates taxi fare based upon miles travelled // and the hour of the day in military time (0-23). var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var milesTravelled = Number(document.getElementById("miles").value); var pickupTime = Number(document.getElementById("putime").value); var cost = baseFare + (costPerMile * milesTravelled); // add the nightSurcharge to the cost if it is after // 10pm or before 6am if (pickupTime >= 22 || pickupTime < 6) { cost += nightSurcharge; } if((document.getElementById('miles').value>=0)&&(document.getElementById('putime').value>=0||<=24) { alert("Your taxi fare is $" + cost.toFixed(2)); } else{return 0;} } </script> Code: <html> <head> <style> .errorWrapper {padding:0; margin:0; list-style-type:none; position:relative;} .errorBox {padding:5px; position:absolute; left:100px; top:100px; background-color:#BADA55; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; box-shadow:2px 2px 2px #808080; -moz-box-shadow:2px 2px 2px #808080; -webkit-box-shadow:2px 2px 2px #808080;} li.errorBox {display:none;} </style> <script type="text/javascript" src="test.js"></script> </head> <body> <a href="#" onClick="show('test')">test</a> <ul class="errorWrapper"> <li id="test" class="errorBox">This should remain hidden until the link is clicked. Lorem ispum dolor sit amet. Placetne tibi? Mihi placet.</li> </ul> </body> <!-- Contents of test.js --> <!-- function show(boxName) {alert(boxName); document.getElementByID(boxName).style.display="block";} --> </html> wtf is wrong with this? I'm brand spanking new to js, so I don't even know how to begin to troubleshoot this. As far as syntax goes I haven't seen any glaring errors, which leads me to believe I'm trying to do something illegal? The alert box shows up, and the boxName variable contains the correct contents (the ID of the element I want to show), so I dunno what the problem is... Quick reproduction of the problem above. When using anonymous wrappers (I guess they are called like that), what does "()" part do at the end of the stack? An example: Code: ( function() {} ) () //Here! What does it do and how can we use it? Is there a particular term for writing functions in this manner? I'm interested in doing some reading up on it but don't quite know what to search for. Code: (function(msg){ document.write(msg); })("What's that smell?"); I am just learning the basics and am trying to figure out timing with setTimeout() Code: <script type="text/javascript"> document.write("<p>" + Date() + "</p>"); setTimeout("document.write('Hello There World');", 2000); setTimeout("document.write("<p>" + Date() + "</p>");", 2000); </script> the 1st document.write works and the 1st setTimeout() works, but then I add the fourth line and the page will not load. Why does it not like my 4th line : "setTimeout("document.write("<p>" + Date() + "</p>");", 2000);"? |