How To Validate Multiple JS Variables
Jun 29, 2010The following works in php but not in javascript.
if((dobyear==false) && (dobmonth==false) && (dobday==true))
{
return 'noyearmonth';
}
The following works in php but not in javascript.
if((dobyear==false) && (dobmonth==false) && (dobday==true))
{
return 'noyearmonth';
}
I have a JS which validates the correct format for postcodes (or zip) on an html form - works fine.But what I want to do is to use a JS to see if a website visitor is eligible for a particular service on their postcode / zip - ie the first general part on the code. For example if they type L15****, or L16**** or L18 (where the asterisk could be anything) it pops up the alert box with a message saying "Yes eligible" but any other code returns "No sorry not eligible" - eg L19**** it returns nope.I've tried hacking the code that validates to format and can manage it for just the first character - ie the L but I'm totally lost after that. I don't know if hacking the below will work.
View 1 Replies View RelatedI have a form that I am using to page people. I have several fields created, so that I can insure that users enter all the different fields instead of just having a message box. I am using skytel to page the people. I am not an expert in java scripting. I have created a script, but can't get everything to work properly. I have a function created that will take all the values from the fields and put them into one. I also have a javascript that does data validation. The only problem is that they only work independently- I can't seem to get both of them to work. If anyone is interested in assisting, I will include the entire HTML file(about 80 lines), but thought I would ask for assistance first.
View 1 Replies View RelatedIs it possible to assign multiple variables at once? For example:
var int1,int2,int3,int4,int5 = 0
I'm just wondering because I did this without thinking and my program never gave me an error and everything worked fine. Is it because these variables are set to 0 by default or what? If it does work, are there any other languages that this works in such as vbscript?
I'm trying to pass multiple variables using a url on a Java function call.
the code I have that passes the 1 variable is:
function HandleChange() {
parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text;
}
which passes the chosen data (being loaded from a database) from a drop down box on an onchange event in asp script.
What I want to do is pass multiple variable via the above url script that the next page will get by the request.querystring method.
something like this:
function HandleChange() {
parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text + "address=" varAddress.value;
}
I am trying to validate the text fields in this form.
Code:
In my head section I have
Code:
I'm having a problem passing a variable through a URL because the
variable is supposed to hold a URL that has a variable of its own.
Here is an idea of what I'm trying to do:
href="javascript:
newWin('/vcrc/exitvcrc.jhtml&newURL=http://www.something.net/default.asp?sponID=ETC','NowLeaving',駼',
餠', 'no', 'auto','no');"
So, pretty much, the page I'm sending the variable to think there's two
variables (newURL and sponID), but sponID is part of the URL.
I'm trying to pass data to my mySQL database, but I'm doing that 2 jQuery scripts:User comes on my page where there is a list with some values, e.g 530, 532, 534 etc etc ..User clicks on one of them, this link is using the jQuery to get another php file which get's the data from my DB and list it below the first list, here's the code for this:
$('#letter-e a').click(function(){
$.get('e.php', {'depot': $(this).text()},function(data){
$('#dict').html(data);
[code].....
So the second list is another step that can't be avoided to get the final result. In other words, i'ts another list where the user has to chose one of the items from the list to see the final result, I've added this code inf the 'e.php' file:
$('#letter-f a').click(function(){
$.get('f.php', {'date': $(this).text()},function(data){
$('#entry2').html(data);
[code].....
The problem is that my 'f.php' only gets 1 variable value, but I'll need 2 or more (maybe in the futur), how to pass multiple variables to a php file using jQuery?
I'm using AJAX to, on the click of a button, run a PHP script that dynamically generates a new line of text, and passes that to the script.The PHP script, new_sentence.php, just echos out the sentence.This works fine.But what I would like to do is for the PHP script to dynamically change JavaScript variables.how to pass multiple variables from PHP to JS.I can, of course, pass one by having the PHP script echo anything, and then use JS to set the variable to the PHP output. But what if I wanted to set two or three JavaScript variables at once?Here's my code in the HTML page that contacts new_sentence.php:
Code:
function ajaxRefresh(){
var ajaxRefresh;
ajaxRequest = new XMLHttpRequest();[code].....
When I press the "Refresh" button on the HTML page, it runs the ajaxRefresh function, which calls new_sentence.php. Then, once it gets the response, it changes the text of the element named "div" to whatever text the new_sentence.php echos.I'd like to figure out how to get a couple of variables.I would imagine this is simple. how to set the variables in PHP and then how to retrieve them in JS.
Is it possible to pull multiple variables from a single dropdown menu selection?
Example:
I have this:
function material_choices_menu() /* Provides Specific Gravity for various materials */{
var data = "Material <select name='material'>";
data += "<option value='.926'>CYCOLAC MG47 (ABS)</option>";
data += "<option value='1.050'>CYCOLAC MG47MD (ABS)</option>";
data += "<option value='.958'>CYCOLAC T (ABS)</option>";
data += "</select>";
document.write(data);
}
I'd like to have multiple option values:
function material_choices_menu() /* Provides Specific Gravity for various materials */{
var data = "Material <select name='material'>";
data += "<option value1='.926', option value2='.005-.008'>CYCOLAC MG47 (ABS)</option>";
data += "<option value1='1.050', option value2='.005-.008'>CYCOLAC MG47MD (ABS)</option>";
data += "<option value1='.958', option value2='.005-.008'>CYCOLAC T (ABS)</option>";
data += "</select>";
document.write(data);
}
I plan to use the first value in some math formulas to determine weights and the rest of the values will just be shown as data for the user and/or possibly a link to the datasheet for the material selected.
I am creating a quote calculator as a mobile app using the JQuery Mobile plugin in Dreamweaver CS5.5. This supports HTML5 & Javascript.
I have included a drop down list in which the user selects a specific Annual Volume. I have 2 different calculations that need to be done based on the users selection. Different calculations meaning that I need 2 different number values assigned to the option.
For Example:
Calculation #1 (I'm calculating what the Run Quantity is based on what the user selects as the Annual Volume. If user selects an Annual Volume of 150,000 then the calculated result for Run Quantity needs to be 3500)
HTML for this scenario:
<li data-role="fieldcontain">
<p><span class="ui-listview-inset">Annual Volume:</label>
<select name="annualvolume" id="annualvolume">
onChange="Calculate();">
[Code].....
Currently I am simply having the user enter the annual volume twice so I can do the 2 calculations, but this is really clunky and not ideal.
I'm new here, and new to js. Here is my problem: I have written out a code to make an image switch from state 0 to 1 and back to 0 again (an eye blink). The code works fine, but I would like to write the functions with arguments so it could be applied to more images. I have tried for a few hours (and searched forums) and am getting no where. Here's my code.
Code:
function home_blinkDown()
{
//alert('blink down');
var t = setTimeout("home_blinkSwap('home_js', 'images/main/home_blink.png')", 2000);
[Code]...
I've recently begun using AJAX on my website and have ran into a problem.My webpage: catalogue.php contains a category variable named $cid which the page GETS in order to display products from the correct category. This works fine.I now want to implement a drop-down box to sort by price, name, newest etc...I have tested the AJAX out with a dropdown box for changing the category and it works fine, this is because it is only passing one variable which it gets via the javascript "this.value".
The sort by price box requires two variables to be passed .I can pass the "this.value" which tells the javascript function I want to sort by price/newest/etc but I cannot figure out how to pass the category variable ($cid) so that when the xmlhttp.open calls the url: getSort.php it passes both pieces of info.My javascript is:
Code:
function showSort(str)
{
var cat = <?php echo $cid ?>;[code].....
I wanted to validate the credit card numbers (I know that's not necessarily safe but I'm living recklessly and we have SSL on this )...
I found some javascript methods but I already have an "onclick" event on my submit button (to make sure people agree to the cancellation policy)....
Is there a way to multitask and do all those things with one script?
I have multiple triggers and I am trying to pass variables via a "rel=" tag (which are unique id's) for each trigger I can get most of it working, problem is that since there are multiple triggers with id="newsTrigger" only the first listed trigger works Using PHP/mySQL. An example trigger is:
while loop{
echo '<span id="newsTrigger" style="font-size:0.8em;" rel="'.
$rowNewsid[$counter].'"><a href="'.$rowNewsPermalink
[$counter].'">'.substr($rowNewsHeadline[$counter],0,40).'</a></span>';
}
The above outputs a large number of rows with the same span id of "newsTrigger". When a user mousesover any of the newsTrigges I am trying to get an ajax dialog to load up content based on the id that is being passed through the rel tag. How do I do this? The javascript so far is:
<script>
$(document).ready(function(){
$("#newsTrigger").mouseover(function() {
var newsid = $(this).attr("rel");
[Code].....
I was wondering how you would list multiple variables after a equal ==?
Example....
if ( pathname == schoolinformation, chaplainchatter)
$('#button_newspress_archive,#button_tech_college,#button_parent_portal,#button_transition_portal,#button_6th_form,#button_connect,#button_vacancies,#button_vle_login').css('display', 'none');
$('#school_information_sub').css('display', 'block');
if ( pathname != schoolinformation, chaplainchatter)
$('#school_information_sub').css('display', 'none');
Or even list multiple URL's within the variables?
Example
....
var schoolinformation = '/st-paul-s-website/school-information/school-news/headteachers-headlines', '/st-paul-s-website/school-information/school-news/chaplain-chatter-headlines';
I have been working on a few budget scripts that I can access from the web in using HTML. My problem is that when variable values change I need to change these values in all of the HTML files on the server. I know that there is a way to declare global variables in a single file and use those values in another file but I have not been able to find any information that tells me exactly how to do this. I have tried to put it together on my own using what little informaiton I have been able to find but have not been able to get this to work. Is there a more detailed referance that I can find somewhere or does anyone know what steps I need to take to make this happen?
View 13 Replies View RelatedI am trying to make an image swap to another image, based on two variables.
i.e. Change an image of a blue car with silver wheels to a red car with black wheels.
The variables are the 1. colour of the car and 2. colour of the wheels. The visitor to the page will click on a coloured car icon to swap the image to the correct coloured car and then on a coloured wheel icon to change the wheel colour.
I have pre-prepared jpegs of all of the combinations of car/wheel colour.
Not sure at all about how to do this, or even if Javascript is the right way to go.
First off I didn't know whether to post this here or in the PHP section since it deals with both, but mostly JS. I have a PHP scraper that scrapes the job title, company name and location from a website and stores them in separate arrays. These values are then extracted out one at a time from the array and stored into a string, that is then passed to a Google Maps API.
I can make this successfully happen once, the thing is I need to do it multiple times. I have an idea on what I should do but don't really know how to implement it (correctly). The idea I had was to create a function in the JavaScript section that accepts three values from PHP. This function would be called in my PHP for loop that extracts the values from the array into a string. The thing that confuses me is that the Map function is called via <body onLoad="initialize()">. Here's the link to my code (http://pastebin.com/rTfzJM16)
I have used AJAX lots before and I wondered if it was possible to set variables from an AJAX file E.g. an ajax file could set
var set1 = 10;
var set2 = 55;
with both variables coming from an external file called by AJAX. Which JS side perform the request and the format of the file that is requested.
I am currently working on a function that will allow the user to search for an event by date and category. I've been using the w3schools exercise as an example but i wish to pass 2 pieces of data instead of one and am not sure how to do so. I'm sure similar posts have been raised before and i apologise if this type of question has already been answered but i could't find it in the forum index.
<FORM name="myForm">
<INPUT type="text" readonly name="MyDate2" value="Click for Calender" onClick="toggleCalendar('MyDate2')"size="15">
Select a Classification:
<select name="Classification2">
[Code]...
Even just point me in the direction of a good article or tutorial, i've been banging my head against it for 2 days so i'm very willing to take a few hours to go through a tutorial
I know that this must be quite trivial to most of you, but my skills
in JavaScript are weak.
I am looking for a way to validate all forms throughout a website
through one validation script.
How do I determine the form's name (or id) value to implement
conditional validation?
i.e. if (form1) { validate like this }; if (form2) { validate like
this };
I've a page that has 2 forms. If the user clicks the bottom form the validations appear and everything goes red but the Top form is a required field but it doesn't as it's a separate form. How can I validation form0 and form1 together to show to the user the required fields. When the user clicks form0 it goes over to a pagedLIst, the user returns and textfield gets populated with the product that as selected. So when they hit form1, that value gets passed through as a hiddenfield..
<form id="form0">
...text box input to search for your product, returns to this page populated the found product
<input class="button" id="FindProduct" type="submit" value="Find Product" name="action"/>
[Code].....
I have 30 groups of checkboxes and want to validate that the user select at least one checkbox from any group meaning if he selected one checkbox from the first group and nothing from the other 29 the form should be valid. I tried different solutions but none worked.
View 1 Replies View RelatedI am creating a form that requires validation feedback in several languages. Is there an easy way to set this maybe with a variable or something?The form used for the different languages is always the same, everything is loaded in the correct language with a variable $lng. I just don't know how to do this for the validate plugin.What i could think of was maybe an include with a test if $lng == X and then include the correct javascript containing the rules and different messages for the different languages?
View 1 Replies View RelatedI have a text field where a user can enter either a(n):American zip code (example: "02475")Canadian zip code (example: "A3F 4G6")A "city/state abbreviation" combination (example: "Toronto, ON", or "Las Vegas, NV")For the most part, users don't have much of a problem with the first two criteria, but some people have some trouble with the third, either by entering simply a state ("NB", or "Texas"), a city, or spelling out the state name "Chicago, Illinois". I need to put together some validation that makes sure that:
If the entered text is not an american or canadian zip code (IOW, if the entered text contains no numbers at all - in that case, move on to the next validation check)Check to see if the third to last character is non alphanumeric (if they entered the city/state combination correctly, there would be some sort of non-alphanumeric separator between the city and state abbreviation)if the entered text doesn't fit the criteria, return the error.
function hasNumbers(string) {
var regex = /d/g;
return regex.test(string);
}
[code]....