:haha:
Berichten: 482
avatar
Offline Stuur privebericht
Goede dag cp leden ik ben bezig met een register script in javascript maar hij doet alles goed behalve 1 klein ding
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$(document).ready(function()
{
    $("#register_form").submit(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#aangemeldtekst").removeClass().addClass('messagebox_form').text('Account aan maken').fadeIn(1400);
        //check the username exists or not from ajax
        $.post("register/ajax_register.php",{ user_name:$('#username').val(),pass:$('#pass').val(),pass2:$('#pass2').val(),mail:$('#mail').val(),mail2:$('#mail2').val(),regels:$('#regels').val(),rand:Math.random() } ,function(data)
        {
          if(data=='yes') //if correct login detail
          {
              $("#aangemeldtekst").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je bent zojuist aangemeld <?=$_POST['username'];?>  Acctiveer je mail').addClass('messageboxok_form').fadeTo(900,1,
              function()
              { 
                   //redirect to secure page
              });
              
            });
          }
         
          else
          {
              $("#aangemeldtekst").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je kon je niet aan melden probeer het opnieuw...').addClass('messageboxerror_form').fadeTo(900,1);
            });        
          }
                
        });
         return false; //not to post the  form physically
    });
    //now call the ajax also focus move from 
    $("#register_form").blur(function()
    {
        $("#register_form").trigger('submit');
    });
});


Hij laat de ingevoerde naam niet zien bij de melding
Laatst gewijzigd door arendjee op 2011-05-28 03:30:21
28-05-2011 00:57
Dit topic is 252 keer bekeken door 48 verschillende leden
Reacties op: "Register"
1
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
der kan slotje op zie het probleem al ben een else vergeten
this ook al laat denk egt bed tijd

Nieuwe reactie samengevoegd met originele reactie op 28.05.11 03:30:54:
Ik heb een ander probleem dus heb die vervangen voor de oude
28-05-2011 01:03
Rapifia Europe
Berichten: 3716
avatar
Offline Stuur privébericht
Je weet dat dit jQuery is en géén JavaScript?
Daarnaast heb je alles wel een beetje slecht geprogrammeerd, zie mijn verbeter code:

Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<script type="text/javascript">
    $(function(){
        $(
"#register_form").submit(function(){
            
//remove all the class add the messagebox classes and start fading 
            
$("#aangemeldtekst").removeClass().addClass("messagebox_form").text("Account aan maken").fadeIn(1400); 
            
//check the username exists or not from ajax 
            
$.ajax({
                
type"POST",
                
url"register/ajax_register.php",
                
data"user_name=" + $("#username").val() + "&pass=" + $("#pass").val() + "&pass2=" + $("#pass2").val() + "&mail=" + $("#mail").val() + "&mail2=" + $("#mail2").val() + "&regels=" + $("#regels").val() + "&rand=" Math.random(),
                
success: function(msg){
                    if(
msg == "yes"){ //if correct login detail
                        
$("#aangemeldtekst").fadeTo(200,0.1,function(){  //start fading the messagebox
                            //add message and change the class of the box and start fading
                            
$(this).html("Je bent zojuist aangemeld " + $("#username").val() + ". Activeer je mail").addClass("messageboxok_form").fadeTo(9001, function(){
                                
//redirect to secure page
                            
});
                        });
                    } else{
                        $(
"#aangemeldtekst").fadeTo(2000.1, function(){ //start fading the messagebox
                            //add message and change the class of the box and start fading
                            
$(this).html("Je kon je niet aan melden probeer het opnieuw...").addClass("messageboxerror_form").fadeTo(9001);
                        });
                    }
                }
            });
            return 
false//not to post the  form physically 
        
}); 
        
//now call the ajax also focus move from  
        
$("#register_form").blur(function(){
            $(
"#register_form").trigger("submit"); 
        }); 
    });
</script>


Als het goed is moet die werken.
Denk voortaan aan het volgende:
- Netjes intabben GEEN spaties!
- Accolades op dezelfde regel om verwarring te voorkomen
- Gebruik één type quotes voor JavaScript / jQuery (ik raad de dubbele aan)
- Gebruik spaties na een nieuwe parameter (dus niet 2,3,3,4 maar 2, 3, 3, 4)
- Gebruik op het begin $(function(){ i.p.v.
$(document).ready(function(){
- Geef bij een Ajax request ALTIJD alle parameters op, hoe ik de request er nu in heb gezet is de juiste manier.

Succes ermee.
28-05-2011 08:53
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
Thnx lars ik ga der mee verder

Nieuwe reactie samengevoegd met originele reactie op 28.05.11 16:12:02:
Je bent zojuist aangemeld Acctiveer je mail
blijft die aangeven
28-05-2011 15:14
Rapifia Europe
Berichten: 3716
avatar
Offline Stuur privébericht
Dan is het de fout van jouw PHP script .
Die moet namelijk "yes" als output geven. Als dat script altijd yes als output geeft zal je altijd die melding ontvangen.
28-05-2011 17:14
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
neej de php is goed
maar hij geeft de naam die ingevoert is niet aan
dat bedoel ik
28-05-2011 17:18
Rapifia Europe
Berichten: 3716
avatar
Offline Stuur privébericht
Heb je wel een veld met als id username?
Geef anders je hele script incl. PHP eens.
28-05-2011 17:51
lvfeo = wijsheid
Berichten: 336
avatar
Offline Stuur privébericht
@L.groot's 1e post jquery is javascript (een library ervan)
28-05-2011 17:54
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
This maar een test script hoor zodra het werkt word het omgezet naar database dingen etc

ajax_register.php
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$existing_users
=array('roshan','mike','jason'); 
$user_name=$_POST['user_name'];
$existing_mail=array('demo@live.nl','test@lol.nl','weetniet@live.nl'); 
$mail_name=$_POST['mail'];
$regel $_POST['regels'];

if (
$_POST['pass'] != $_POST['pass2'])
{
    echo 
"no";
}elseif (
$_POST['mail'] != $_POST['mail2'])
{
    echo 
"no";
}elseif (
in_array($user_name$existing_users))
{
    
//user name is not availble

    
echo "no";
}elseif (
in_array($mail_name$existing_mail))
{
    
//user name is not availble
    
echo "no";
}elseif(empty(
$regel))
{
    echo 
"no";
}else

{

    echo 
"yes";
}


?>


Verder ik weet het kan makkelijker maar het is meer om te testen eerst zodat ik het onder de knie heb als het werkt schrijf ik het helemaal over om korter / makkelijker t emaken

register.php
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">


$(document).ready(function()
{
 
    $("#username").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Kijken in de database').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/user_availability.php",{ user_name:$(this).val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Deze gebruikersnaam bestaat al').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
              else      {
              $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Deze naam is nog niet in gebruik').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});

$(document).ready(function()
{
 
    $("#pass").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#passmessage").removeClass().addClass('messagebox').text('Wachtwoord check').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/pass_check.php",{ user_name:$('#username').val(),pass:$('#pass').val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#passmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je wachtwoord is het zelfde als je gebruikersnaam').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
          
          else if(data=='min') //if username not avaiable
          {
              $("#passmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je moet minimaal 8 tekens in je wachtwoord').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
          else if(data=='empty') //if username not avaiable
          {
              $("#passmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je moet wel wat invullen').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
else          {
              $("#passmessage").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Dit wachtwoord is goed').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});

$(document).ready(function()
{
 
    $("#regels").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#regelbericht").removeClass().addClass('messagebox').text('Regelcheck').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/regel_check.php",{ regels:$('#regels').val()} ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#regelbericht").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Accepteer de regels').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
         
else          {
              $("#regelbericht").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je heb de regels geaccepteert').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});


$(document).ready(function()
{
 
    $("#pass2").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#herhaalmessage").removeClass().addClass('messagebox').text('Wachtwoord check').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/pass_herhaal.php",{ pass:$('#pass').val(),pass2:$('#pass2').val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#herhaalmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je wachtwoorden zijn niet gelijk').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
          
          
else if(data=='empty') //if username not avaiable
          {
              $("#herhaalmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je heb geen wachtwoord ingevult').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
          
          
else          {
              $("#herhaalmessage").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je wachtwoorden zijn gelijk').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});

$(document).ready(function()
{
 
    $("#mail2").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#mail2message").removeClass().addClass('messagebox').text('Mail check').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/mail_herhaal.php",{ mail:$('#mail').val(),mail2:$('#mail2').val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#mail2message").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je mail adressen zijn niet identiek').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
          
          
else    if(data=='empty') //if username not avaiable
          {
              $("#mail2message").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je moet wel wat invullen').addClass('messageboxerror').fadeTo(900,1);
            });        
          } else
                {
              $("#mail2message").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Je email adrres zijn gelijk').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});

$(document).ready(function()
{



    $("#mail").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#mailmessage").removeClass().addClass('messagebox').text('Kijken in de database').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("register/mail_availability.php",{ user_name:$(this).val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
              $("#mailmessage").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Deze mail is al ingebruik').addClass('messageboxerror').fadeTo(900,1);
            });        
          }
else          {
              $("#mailmessage").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Mail naam is nog niet in gebruik').addClass('messageboxok').fadeTo(900,1);    
            });
          }
                
        });
 
    });
});

 $(function(){
                            
                var MyFirstVar = 'onbekende' ;

        $("#register_form").submit(function(){

            //remove all the class add the messagebox classes and start fading 
            $("#aangemeldtekst").removeClass().addClass("messagebox_form").text("Account aan maken").fadeIn(1400); 
            //check the username exists or not from ajax 
            $.ajax({
                type: "POST",
                url: "register/ajax_register.php",
                data: "user_name=" + $("#username").val() + "&pass=" + $("#pass").val() + "&pass2=" + $("#pass2").val() + "&mail=" + $("#mail").val() + "&mail2=" + $("#mail2").val() + "&regels=" + $("#regels").val() + "&rand=" + Math.random(),
                success: function(msg){
                    if(msg == "yes"){ //if correct login detail
                        $("#aangemeldtekst").fadeTo(200,0.1,function(){  //start fading the messagebox
                            //add message and change the class of the box and start fading
                                                        



                            $(this).html("Je bent zojuist aangemeld "+MyFirstVar+" Activeer je mail").addClass("messageboxok_form").fadeTo(900, 1, function(){
                                //redirect to secure page
                            });
                        });
                    } else{
                        $("#aangemeldtekst").fadeTo(200, 0.1, function(){ //start fading the messagebox
                            //add message and change the class of the box and start fading
                            $(this).html("Je kon je niet aan melden probeer het opnieuw...").addClass("messageboxerror_form").fadeTo(900, 1);
                        });
                    }
                }
            });
            return false; //not to post the  form physically 
        }); 
        //now call the ajax also focus move from  
        $("#register_form").blur(function(){
            $("#register_form").trigger("submit"); 
        }); 
    });
</script>
<style type="text/css">
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
}
.top {
margin-bottom: 15px;
}
.messagebox{
    position:absolute;
    width:auto;
    margin-left:30px;
    border:1px solid #c93;
    background:#ffc;
    padding:3px;
}
.messageboxok{
    position:absolute;
    width:auto;
    margin-left:30px;
    border:1px solid #349534;
    background:#C9FFCA;
    padding:3px;
    font-weight:bold;
    color:#008000;
    
}
.messageboxerror{
    position:absolute;
    width:auto;
    margin-left:30px;
    border:1px solid #CC0000;
    background:#F7CBCA;
    padding:3px;
    font-weight:bold;
    color:#CC0000;
}

.messagebox_form{
    position:absolute;
    width:auto;
    border:1px solid #c93;
    background:#ffc;
    padding:3px;
}
.messageboxok_form{
    position:absolute;
    width:auto;
    border:1px solid #349534;
    background:#C9FFCA;
    padding:3px;
    font-weight:bold;
    color:#008000;
    
}
.messageboxerror_form{
    position:absolute;
    width:auto;
    border:1px solid #CC0000;
    background:#F7CBCA;
    padding:3px;
    font-weight:bold;
    color:#CC0000;
}

</style>
</head>
<body>
<form method="post" action="" id="register_form">

<p>Welkom op true-crime Zin om mee te spelen meld je nu aan. <small>Let er op er komt een activatie link naar je mail</small></p>
<div>
<span id="aangemeldtekst" style="display:none"></span>

<br><br><br>
</div>

<table >
   <td width="200">User Name :</td>  <td width="200"> <input name="username" type="text" id="username" value="" maxlength="15" /></td>
     <td width="200"><span id="msgbox" style="display:none"></span></td>
</table>

<table >
     <td width="200">Mail adres:</td>  <td width="200"> <input name="mail" type="text" id="mail" value="" maxlength="90" /></td>
    <td width="200"> <span id="mailmessage" style="display:none"></span></td>
</table>

<table >
     <td width="200">Herhaal Mail:</td>  <td width="200"> <input name="mail2" type="text" id="mail2" value="" maxlength="90" /></td>
    <td width="200"> <span id="mail2message" style="display:none"></span></td>
</table>

<table >
     <td width="200">Wachtwoord:</td>  <td width="200"> <input name="pass" type="password" id="pass" value="" maxlength="15" /></td>
    <td width="200"> <span id="passmessage" style="display:none"></span></td>
</table>


<table >
     <td width="200">Herhaal Pass:</td>  <td width="200"> <input name="pass2" type="password" id="pass2" value="" maxlength="15" /></td>
    <td width="200"> <span id="herhaalmessage" style="display:none"></span></td>
</table>

<table >
     <td width="400" align="left"><input name="regels" type="checkbox" id="regels" /> Accepteer de regels</td>
    <td width="200"> <span id="regelbericht" style="display:none"></span></td>
</table>

<table>
     <td col colspan="10" align="center"><input name="submit" type="submit" id="aanmelden_form" value="Maak account aan" /> </td>
</table> 
</form>
28-05-2011 17:56
Webdeveloper & Programmeu
Berichten: 1001
avatar
Offline Stuur privébericht
Lars ik vind het leuk en aardig maar probeer niet gelijk tek rijgen met die punten van je:
Als het goed is moet die werken.
Denk voortaan aan het volgende:
- Netjes intabben GEEN spaties!
- Accolades op dezelfde regel om verwarring te voorkomen
- Gebruik één type quotes voor JavaScript / jQuery (ik raad de dubbele aan)
- Gebruik spaties na een nieuwe parameter (dus niet 2,3,3,4 maar 2, 3, 3, 4)
- Gebruik op het begin $(function(){ i.p.v.
$(document).ready(function(){
- Geef bij een Ajax request ALTIJD alle parameters op, hoe ik de request er nu in heb gezet is de juiste manier.

Het is de manier hoe je het zelf wilt doen en wat jij makkelijker vind, ga niet beweren dat je MOET intabben MOET accolades opzelfde regel neerzetten.

PLEASE STOP!
28-05-2011 19:04
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
Quote: L.Groot

Heb je wel een veld met als id username?
Geef anders je hele script incl. PHP eens.




hij showt gwn de "post " niet>.< als ik bijvoorbeeld bij die var onbekend zet laat die wel zien ..
28-05-2011 20:22
Reageer op: "Register"
1
Je kan niet reageren omdat je niet bent ingelogd. Inloggen of Aanmelden