|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
javascript, arrays, mysql, php
Ok...
This is for an input box, to create a new 'user id' i'll say, for the system. The user id must consist of a letter from a predefined (in a table in the db) agency code, and four numbers. My problem is that the code i have so far can do everything but select the agency code letter from only the ones existing in the data base already. This is the input box in a php file that is viewed when the page is accessed: User ID: <input name="divcode" onChange="isValidNEWUI(this); value="start"> This is a seperate page, the validation code in java script which is found in an include file: function isValidNEWUI(field) var userIDPattern = /^([A-V]{1})(d{4})/; var matchArray = field.value.match(userIDPattern); if(matchArray == null) { alert("Not in valid format!); field.focus(); field.select(); return false; } checkdivcode() } Now, this is a query i can run, to get all the information from the db about the user ID first letter's available, but i do not want a select box, and i don't know how to make the javascript test to see if the pattern matches one of these letters instead of using the A-V. $idLetter = mysql_query("SELECT code_id, ed_name FROM codebook WHERE code_type = 'DI' ORDER BY ed_name' "); while($divLetters=mysql_fetch_array($divLetter)) { echo"<option value="$divLetters[0]">$divLetters[1]n"; } Can someone help? pretty please??? |
|
#2
|
|||||
|
|||||
|
RE: javascript, arrays, mysql, php
Well, why don't you also output the letters that are OK?
Code:
function isValidNEWUI(field, letters)
{
var userIDPattern = new RegExp("^["+letters+"]\d{4}");
var matchArray = field.value.match(userIDPattern);
if(matchArray == null) {
alert("Not in valid format!);
field.focus();
field.select();
return false;
}
checkdivcode()
}
php Code:
(I'm not sure if this exact code works, but you get the idea |
|
#3
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
That is what i've been trying to work on, or something similar...
Could you explain the input name? what do you mean by the code? Wouldn't it be named letters too??? |
|
#4
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
<input name=thecode> should be <input name=divcode>, sorry
|
|
#5
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
Ok, i'm close, but it's the JavaScript line where +letters+ is that i think is now causeing troubles...
Is it maybe because the letters of the agencies, say CLEM are being passed like that, and now it's checking to see if they are all CLEM and not jsut C??? hope that made sense. i'm so fustrated!!! |
|
#6
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
Hmm, it shouldn't.. Can you add
alert("^["+letters+"]\d{4}"); as the first line of isValidNEWUI, and see what it looks like? It should be ^[CLEM]d{4} |
|
#7
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
hee hee
I already tried putting letters in the alert message already there, and it worked fine. I tried yours too with the pattern, and it comes out correctly... I think it is because it is now looking for all of CELM? not just C or just M??? I was thinking maybe i needed to make it into a javascript string, and then break the string into an array... or something, but it's not working out that way either so i'm kinda lost. But letters is passing through into the javascript correctly. Just not doing what i want it to. heh |
|
#8
|
|||||
|
|||||
|
RE: javascript, arrays, mysql, php
Hmm, that is strange. For one thing, I tried the following:
php Code:
And it works perfectly on my browser. Also, according to docs, [xyz] means "A character set. Matches any one of the enclosed characters. For example, '[abc]' matches the 'a' in "plain". Basically, what I'm trying to say is that I've no clue what the problem might be |
|
#9
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
ok, well umm... i'll keep trying.
Thanks anyways. |
|
#10
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
Got it!!!
thanks! |
|
#11
|
|||
|
|||
|
RE: javascript, arrays, mysql, php
So what was it? Please share your experience with the rest of the group ;)
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > javascript, arrays, mysql, php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|