:haha:
Berichten: 482
avatar
Offline Stuur privebericht
Ik ben nu aan het leren met ajax / javascript en liep tegen een probleem aan maar lars heb daar mee geholpen maar nu zit ik met nog een vraagje is het mogelijk om in ajax/javascript php echo's / variables te gebruiken ? zodat ik de site volledig in ajax / javascript kan doen .
28-05-2011 15:59
Dit topic is 152 keer bekeken door 26 verschillende leden
Reacties op: "Variables"
1
thexeroxprojects.be
Berichten: 352
avatar
Offline Stuur privébericht
Ja zeker

Bv:
Code | Selecteer Alles
minimaliseren
1
2
3
<script type="text/javascript">
var MyFirstVar = <?php echo 'Hier komt mijn eerste var'?> ;
</script>
28-05-2011 16:12
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
en hoe kan ik die dan bijvoorbeeld hier in aan roepen

Code | Selecteer Alles
minimaliseren
1
$(this).html("jeverdient 'hier moet de var' euro").addClass("messageboxok_form").fadeTo(9001, function(){
28-05-2011 16:15
thexeroxprojects.be
Berichten: 352
avatar
Offline Stuur privébericht
Code | Selecteer Alles
minimaliseren
1
2
3
4
<script type="text/javascript">
var MyFirstVar = <?php echo 'Hier komt mijn eerste var'?> ;
$(this).html("Je bent zojuist aangemeld "+MyFirstVar+" Activeer je mail").addClass("messageboxok_form").fadeTo(900, 1, function(){ 
</script>
28-05-2011 16:17
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
oehhw thnx ik ge even kijken

Nieuwe reactie samengevoegd met originele reactie op 28.05.11 16:22:58:
Tooen werkte het hele script nie meer
28-05-2011 16:18
thexeroxprojects.be
Berichten: 352
avatar
Offline Stuur privébericht
post je volledige script eens
28-05-2011 16:24
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
http://pastebin.com/54w8pAW9

Ik weet dat het korter kan maar is meer om te testen en het beetje onder de knie te krijgen
28-05-2011 16:26
thexeroxprojects.be
Berichten: 352
avatar
Offline Stuur privébericht
Je var moet binnen "$(document).ready(function()
{" + op regel 8 staat een; teveel
28-05-2011 16:28
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
hmmz heb het veranderd maar nu doet nog niets het

Nieuwe reactie samengevoegd met originele reactie op 28.05.11 16:33:43:
Code | Selecteer Alles
minimaliseren
1
var MyFirstVar = <?php echo $_POST['username']; ?> ;


als dat er bij staat werkt de rest niet meer>.<
28-05-2011 16:30
thexeroxprojects.be
Berichten: 352
avatar
Offline Stuur privébericht
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 = '<?php echo $_POST["username"]; ?>' ;

        $("#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>

Dit werkt;
28-05-2011 16:39
:haha:
Berichten: 482
avatar
Offline Stuur privébericht
@therox

Je bent zojuist aangemeld Activeer je mail
maarja ik ga ff verdxer kijken iedergeval thnx
weet nu hoe je een var der in krijgt
28-05-2011 16:54
Reageer op: "Variables"
1
Je kan niet reageren omdat je niet bent ingelogd. Inloggen of Aanmelden