I have a situation in javascript where (this is inherited code, so I gotta deal with it) a variable is being used without being declared, as
someVar = someExpression ;
The original developer was relying on IE which automagically creates javascript variables for the IDs of all HTML elements, so somewhere in the HTML, there's
<someTAG id='someVar' >blah </someTAG>.
Unfortunately, in Mozilla (Firefox), I get a javascript error indicating that 'someVar' is not defined.
I wanted to check to see if the variable was undefined, then define it
if (undefined == someVar) someVar = document.getElementById("someVar") ;
this gives the same error in Mozilla (undeclared variable). I saw a thread with this exact problem, but it looks like its been archived. Does anyone have the solution to checking in javascript if a name is "undeclared" as opposed to "undefined"???
I'm confused about declaring variables. I see variable explicitly declared with the keyword var, both inside and outside of functions, and I suppose that depending on where it is declared relates to variable scope. BUT, I also see variable used that have not been explicitly declared with var. What determines if a variable needs to be declared?
So I've got this checkbox thing going on, where an array converted with the value of each checkbox in it.It looks like this:
[Code]...
What I want out of this function is the variable newworkdays to use in another function.
How do I access the "newworkdays" outside the function? I've already try to declare the variable outside of the function, though that resulted in that I didn't get the value of the variable inside the function.
I am using a validating form plug in for jquery and I have a question about it. Let this function will be an ex.:
[Code]....
'e' is the name attribute of one form element, but can I choose more elements using jquery (CSS) rules like this: input[name*=e] or how can I do something similar?
The problem is when i will calculate if quantitiy/buyquantitiy is an integer. The reason is that some products can only be seld as 4 items, and if you press 3 wou should get a message that says "Sorry a quantity of 3 are not aviable because there are 4 items in package". Can transfer 2 varibales into the function? Or have anyone any suggestion how to solve this.
I am a newbie to javascript. I have an asp text box which I want to validate for the number of characters entered i.e. I dont want user to enter more than 280 characters in the text box.
I have a form generated from a Perl script. The number of check boxes on the form is unknown until the time the form is generated. The names of the check boxes are created from some values in the database, based upon other user input.......<crazy, I know>
The user must choose at least one check box.
So, how can I write a javascript routine that will perform checking on an unknown number of check boxes.
Can anyone explain why this code fails when the set of checkboxes consists of only one.
myForm.update.length returns 0 instead of 1 with the result that I get an alert box even tho' the one checkbox is checked.
function checkForm(myForm) { var numBoxes = 1*myForm.update.length || 0; for(i=0;i<numBoxes;i++) { if(myForm.update[i].checked == true) return true; } alert("Select one or more part components to update"); return false; }}
I have a requirement whereby I must validate that a string matches one of several patterns:
1. An ISO standard 2 character country code (eg GB, NL) followed by five digits.
2. An ISO standard 2 character country code (eg GB, NL) followed by an X followed by five digits.
3. 3 characters in the range a-z followed by 3 digits followed by 2 characters in a specific set (eg MT, AT, DA).
4. 4 characters followed by a hash (#) followed by 3 characters followed by 3 digits followed by a hash followed by 3 characters.
5. 4 characters followed by a hash (#) followed by 3 characters followed by 3 digits followed by a hash followed by 4 characters.
I have been told that a better way to achieve this than using .charAt is by using something called a regular expression, but I don't really understand them. Can anyone please advise on the above or alternatively point me in the direction of a suitable resource on these regular expression things?
I am trying to write a js that validates a form with two text inputs. The two inputs are: 'D_techA' and 'D_techB'. I just want to add up (sum) the two input fields (which must be positive numbers) and make sure that they add up to exactly 100 (not more and not less). If they do not add up to 100, then an alert should pop up that says "The two values must add up to exactly 100." I have tried and tried to write a js that does this validation (looking at numerous validation scripts posted in this forum and elsewhere) and I just cannot seem to make it work.
I am validating a page (image attached) to make sure that total hours entered do not exceed the allocated amount, which is stored in the database. I have already validated to make sure that they enter a number and that it is not greater than 8.
var returncode = true var inputs = document.getElementsByTagName("INPUT") for(var x=0; x<inputs.length; x++) {
function POvalidator() { var obj = document.Form1; if (obj.PONumber.value == "") { alert("Please enter a value for the PO Number field."); obj.PONumber.focus(); return false; }}
function checkCheckBox(){ if (f.agree.checked == false ) { alert("Tou must agree to the Terms to continue"); return false; }else return true; }
I found some simple code to get a better understanding of validating checkboxes. It validates the checkboxs by their name. Is it possible to validate the checkboxes with the same name but different values? The name of the checkboxes will be an array containing the values of the checkboxes selected.
I have my html like so: <input type="checkbox" name="stuff[]" value="1" onClick="countChoices(this)"> <input type="checkbox" name="stuff[]" value="2" onClick="countChoices(this)"> <input type="checkbox" name="stuff[]" value="3" onClick="countChoices(this)">
And the javascript where I edited "box1=", "box2=", "box3=" is like so: function countChoices(obj) { max = 2;
I have a form that is passed to itself. I was just wondering if there was a way to get this to validate before it passed to itself.I was assuming that as the form doesn't properly submit, I could not use onsubmit="return sValidation()", so I have it on the buttons onclick. Correct assumption or not? Is there a way round this at all and to get it to validate?
I want to check that only letters were entered in a field.formElements[i].value.search(/^[^a-zA-Z]+$/) != -1Will the above line be true if characters other than letters are found?
I am creating this Javascript/XML HTA that is basically a project tracker. I recently added some new fields in the form that are written to the XML file for the project being tracked. This makes the files neither backwards compatible if I use it in a previous version nor forward compatible for future versions. This means if a user is using version 1, I create version 2, he wants to import his old tasks to Version 2, it throws an error. For example if I have a <status> element written in the newest version, but no <status> in the previous, I can no longer use that projects XML file in a previous version.
I tried to use the following code to validate existence of the tag and assign whatever outcome as the variable to write, but it's not working. Theres a few different ways I tried.
I am looking for a little help validating a forms input. On the form are key items which I do not wish to be zero length.
I have wrote the following function:
<script language=javascript> function ValidateLength(oid, min, max) { var txt = document.getElementById(oid); var length = txt.value.length; if(length == 0) { alert("You must enter your reference, Company Name and Contact Name"); } } </script>
However their are still a few issues I would like to work out.
I all it with my forms sumbit event with the following:
However that will only check the length of the item txtRef, how can I check more textbox values? Also how can I stop the form posting if the alert is raised?
I'm working on a site where the name attribute of an input will not be known beforehand. I'd like to be able to modify or extend the validate plugin to set the rules and messages based off of the id of an input instead of using the name.
I'm experimenting with the load() function. It works fine except when I try to validate (using jQuery Validate).
I have a page called "index.php" which contains the bulk of my code (including the jQuery validate call). The load function calls in a div from another page which we'll call foo.php. The page loads fine, but it just won't validate. I've wondered if you simply can't validate a "load"ed page, but I find that hard to believe.
For some reason my form isn't validating. I manage to get the "Please select an option" alert, but it still posts the form. 2 sizes available <SCRIPT language=javascript> function CalculateOrder(form){ if (form.os0.value == "8x10"){ form.amount.value = "90.00"; form.shipping.value = "15.00"; }.....
Here's what I have so far in my validation part However, I need help as to how to validate the following fields when the user clicks the submit button.
I am helping someone out with a form. He wants the name required, easy enough, but then only an email or street address required. I have tried a couple of things and it is not working.
I am trying a very simple code: <script type="text/javascript"> <!--
function validate_form ( ) { valid = true;
if ( document.contact_form.name_mailing.value == "" ) { alert ( "Please fill in the 'Your Name' box." ); valid = false; }
if ( document.contact_form.address_mailing.value == "" || document.contact_form.email_address.value == "") { alert ( "Please fill in the 'Your Information' box." ); valid = false; }
return valid; }
//--> </script>
Am I not using the or operator correctly? I only want to have the address or email required, not necessarily both.