Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 16th, 2003, 03:18 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
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???

Reply With Quote
  #2  
Old April 16th, 2003, 03:31 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
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:
Original - php Code
  1.  
  2. $idLetter = mysql_query("SELECT code_id, ed_name FROM codebook WHERE code_type = 'DI' ORDER BY ed_name");
  3. $letters="";
  4. while($divLetters=mysql_fetch_array($divLetter)) {
  5.     $letters.=$divLetters[0];
  6. }
  7. echo "<form onsubmit="return isValidNEWUI(forms[0].fields.thecode, '$letters')">";
  8. echo "<input name=thecode>";

(I'm not sure if this exact code works, but you get the idea )

Reply With Quote
  #3  
Old April 16th, 2003, 04:43 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
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???

Reply With Quote
  #4  
Old April 16th, 2003, 04:49 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: javascript, arrays, mysql, php

<input name=thecode> should be <input name=divcode>, sorry

Reply With Quote
  #5  
Old April 16th, 2003, 04:59 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
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!!!

Reply With Quote
  #6  
Old April 16th, 2003, 05:03 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
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}

Reply With Quote
  #7  
Old April 16th, 2003, 05:13 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
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

Reply With Quote
  #8  
Old April 16th, 2003, 05:20 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: javascript, arrays, mysql, php

Hmm, that is strange. For one thing, I tried the following:
php Code:
Original - php Code
  1.  
  2. ?>
  3. <script language=JavaScript>
  4.  
  5. function IsOK(field,b)
  6. {
  7.     var userIDPattern = new RegExp("^["+b+"]\d{4}");;
  8.     var matchArray=field.value.match(userIDPattern);
  9.     if (matchArray==null) {
  10.         alert("Not in valid format!");
  11.         field.focus();
  12.         field.select();
  13.     }
  14. }
  15.  
  16. </script>
  17. <input maxlength=5 onchange="IsOK(this, 'abc')">

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 :

Reply With Quote
  #9  
Old April 16th, 2003, 05:27 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
RE: javascript, arrays, mysql, php

ok, well umm... i'll keep trying.

Thanks anyways.

Reply With Quote
  #10  
Old April 16th, 2003, 05:38 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to myraleen Send a message via AIM to myraleen
RE: javascript, arrays, mysql, php

Got it!!!

thanks!

Reply With Quote
  #11  
Old April 16th, 2003, 05:55 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: javascript, arrays, mysql, php

So what was it? Please share your experience with the rest of the group ;)

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > javascript, arrays, mysql, php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek