JQuery :: Pattern Matching Against A List?
Jun 23, 2010<ul
id
="menu-main-navigation"
class
="menu"
[Code]...
<ul
id
="menu-main-navigation"
class
="menu"
[Code]...
I ask the user to enter a time in the formatio 12:30 PM. onChange I
send the string to this function. I'm using alert boxes to test
it...and am always getting the "Does not work" alert box. What am I
doing wrong?
function checkTime(pattern){
if(pattern.value.match(/[0-9] + :[0-9] + [0-9] + [aApP] + [mM]/)) {
alert ("works")
}
else alert(pattern.value + "Does not work")
}
Two fairly basic questions:
I need to supply a method with an array of strings, which will
eventually be used to pattern match against another array of strings.
1. Is there a good way to span multiple lines when creating an array
from a list of strings? (I want the most readable list I can get.)
// The following doesn't seem to work
urlExclusions = newArray(
"my.domain.com/dir1",
"another.domain.com/dir2",
"third.domain.com/blah"
);
2. When I'm looping over the above array in a method, what's the best
way to use these as patterns to match? Does "new
RegExp(urlExclusions[i], "i") do all the necessary escaping of
whatever literals might be in the urlExclusions[i] string? (All
characters in the above strings should be treated as a literals. I
don't intend for that list to be a place to put RegEx.)
Example: I want to do something like this with the list:
for (var i=0; i < urlExclusions.length; i++) {
pattern = new RegExp(urlExclusions[i], 'i');
if (pattern.test('http://my.domain.com/dir1')) {
document.write("Matched");
} else {
document.write("Didn't Match);
}
}
i am having trouble with a program for class hoping someone can point me in the right direction i am supposed to use nested for loops to output 2 seperate webpages one with the first pattern below and then another with the second pattern.
[Code]...
I am trying to make some changes in Prestashop, an ecomerce platform that make use of jQuery library.
I just found out the way they do the onmouse over efect for the different pictures of a particular product.[code]...
I have searched the forum and internet and experimented a lot with .each but couldn't get this to work:I have several divs with id="flash", and I want them all to flash when the site loads. Using this code only the first div flashes:
$(document).ready(function() {
$(window).load(function () {
$("#flash").effect("pulsate", { times:3 }, 1000);
[code]....
I'm trying to do is simple "select all" checkbox script. The problem is, no matter what I seem to do, only first element is matched. $("input:checkbox").attr("checked", true); checks the first box only. Same with: $("input:checkbox").each(... I even tried copying this script directly from the jQuery documentation page: $("div").css("border","9px solid red"); It applies a red border to the first div on my page.. the example in the documentation applies it to all divs.
View 5 Replies View RelatedTrying to hide a table that's a sibling to the anchor to which theclick event is being called. It works, with any element but a tableas a sibling. My code/markup:
<script type="text/javascript">
$(document).ready(function(){
// show/hide details
[code]....
This should be pretty simple one ,yet I can't seem to figure it out. There are posts that are similar to my question on here, but they don't really answer my questions. The a user comes to the page, they're at a URL like such: [URL]..
[Code]...
I came across JQuery when searching for a solution to get matching column height with Divs. I have downloaded JQuery which appears to be one file named jquery-1.3.2.min I also have the following short script that I found, which I believe goes in the head area of the page.
The script works with jquery.
HOW TO DO:
1. I assume I need to rename my download file jquery-1.3.2.min to jquery.js ?
2. Do I need to edit the jquery file somehow in order to get the above script to work?
<div>
</div><div>I just found out that jQuery can match on partials,.. is this correct?</div><div>and if so how do I make it match on the whole text.</div><div>[code]......
im very new to jQuery and have a problem I cant solve by myself. I have an ul li list with items that match a later following div - the match is the id. That id is matching another following div by id. All elements are dynamically generated and can vary in depth. I have a working set with onclick fuctions, but I want to make this working in jQuery.
[Code]...
I have a script that prints out a lot of <tr>'s, each has a different id, let's say it's a number. What i am trying to get is when a user enters numbers in a certain textfield, named #idtext for example, it shows only those <tr>'s whose id numbers matches the entered value and hides the rest. For example, user enters 23 in the text field, rows with id numbers 123, 23, 231 are shown, the rest are hidden, etc.
Atm i have smoething like this, not working:
$("#idtext").change(function(){
var val = $("#idtext").val();
$('tr[id^<>'+val+']').hide();
$('tr[id^='+val+']').show();
});
I am trying to do two emails validate - if they are empty error messages pop up - if the emails address not match error message show up.
So far I done the empty email which look fine but I can't work out the error message when the emails not match:
Here what I have done so far:
Form Page
<tr>
<td bgcolor="#F6F6F6">E-mail<span class="green"> *</span></td>
<td colspan="2" bgcolor="#FFFFFF"><input name="email" type="text" size="40" value="<?php echo $_SESSION["email"];?>" />
[Code].....
I have an ul li list with items that match a later following div - the match is the id. That id is matching another following div by id. All elements are dynamically generated and can vary in depth. I have a working set with onclick fuctions, but I want to make this working in jQuery.This is the raw template:
<div class="mything">
<ul>
<li id="t232">
[code]....
I am trying to match a passed parameter on a url to an area on an image map. So far I can find the correct area using
Code:
$('#mediummap area').each(function(i){
href = $(this).attr('href');
if (href == id) {
alert('Found ID ' + id);
}});}});
But next I need to retrieve the co-ordinates for the Area. I have tried
Code:
coords = $('this').attr('coords');
And
Code:
coords = $('this').coords();
I can not seem to get the value back, just an undefined return. What I want to do is to find the point on the image map and then centre that point with in the viewport for the image (large image, small viewport).
I am trying to use a string for a regular expression pattern. Here is a
test that I set up:
var s="^d{3}-d{3}-d{4}$";
var r=new RegExp();
r.compile(s);
var t="333-333-3333";
alert(r.test(t));
I have tried this with and without the "compile", and also adding the
"/..../" to the beginning and end of the string, but I always get "false".
Can you use a string to represent a pattern...in Javascript?
I am new to javascript and would like to search for the element with id but the element id are changing if i use different navigation in that web page example: C21_W68_V69_notes_struct.text changes to C24_W78_V79_ notes_struct.text or any other name next time hence i would like to search that element using a pattern like notes_struct.text as there exist only one element ending with this pattern. I am using old version IE and would like to use javascript only.
View 5 Replies View RelatedI'm currently doing a javascript course and am working on my coursework, I've come across a roadblock.
Part of the task is to create a pattern match to recognize valid postcodes.[code]...
At a minimum, I'd like to know the official term for what I'm trying to do is called, then I can at least do some reasearch on my own.
While I'm here, how's my coding so far? Anything that screams "bad practice"? or "I could do better"?
I have a single-cell table with a bunch of items within divs like item 1 below. The values in the divs are categories.
Following that (item 2 below), I have several single-row, two-column tables where the first column represents a Name (the item I want highlighted) and the second column is one or more of the category items (subset of item 1).
<div class="view-display-id-attachment_1">
<table>
<tr>
<td>
[Code].....
This doesn't work and I'm hoping to generalize it but I'm not sure if .field-item-* will work.
I have written an ASP.net app that pulls settings from a
database. Part of the setting definition is a regular expression that
I want to use on the client via JavaScript for data validation...
1) Sample code for the setting object:
----------------------------------------------------
function setting(id, name, validationPattern, validationMsg) {
this.id = id;
this.name = name;
this.validationPattern = validationPattern;
this.validationMsg = validationMsg;
}
2) Sample code on the page that creates a new setting object:
----------------------------------------------------
setting(1, 'test', '^d{1,1}$|^d{2,2}$|^100$', 'invalid value');
3) The issue:
----------------------------------------------------
The setting object gets built just fine except the pattern argument
gets escaped by javascript!!!
^d{1,1}$|^d{2,2}$|^100$
GETS ESCAPED TO
^d{1,1}$|^d{2,2}$|^100$ (Notice how the double is now a single )
Is there any way for me to preserve the pattern text as is?
I want to validate the value in a textbox such that the first character should be a symbol like # or $ followed by 2 alphabets which is followed by numbers.I tried a pattern like code...
View 7 Replies View RelatedIm trying to find if a particular html markup pattern (<ROD> ... </ROD>) within a string and if its found then replace it with another string.eg."This is my string and it might <ROD>PartNumber123</ROD> contain HTML markup"So in this case I want to replace "<ROD>PartNumber123</ROD>" with {0}. If there is no <ROD>...</ROD> then dont do anything.Im sure im doing this the wrong way, maybe a regular expression would be best.Although this works its not very clean and I just cant find the correct solution.
function parseData(data){
var r1 = data.indexOf("<ROD>",0);
var r2 = data.indexOf("</ROD>",0);
[code]....
I am trying to do a pattern match and check something in a condition but cant get it to work. The first value changes and I need to check and do something if I get a hit on it.
Code:
var mydata = "?first=one&second=two&third=three";
if (mydata.indexOf("first") == "something")
{
alert("No Hit");
} else {
alert("Hit");
}
Basically I am trying to find out if first is equal to one in the mydata string. My above attempt is not working.
I need to validate three textboxes and it will validate for numbers. How should I change my code to validate three textboxes?
Code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
[code]....
I need to use Javascript to validate 3 textboxes, whereby the users can only key in numbers (because they are phone numbers related fields). If any of the textbox is empty, display an alert message to show which textbox is empty. I do not want to show many alert messages to show that, for example, text1 and text2 are empty, it will show two alert messages. I would need to show one "summarized" alert message instead.Next, check if the textbox matches the pattern (which is to check if it has the skeleton of a phone number). If it is, show an alert message that it is alright. Else, show that it does not match.
I am trying to make an application that displays a pattern of asterisks a certain way. the only output statements I could use are to get the pattern below. My question would be which way to use the nested loop, (do i do while(if else)...
[Code]...