July 1, 2010

How to use jQuery to set value on screen rather than use alert?

Question by Autolycus

I am using the code that I will post below. I generates the password and works fine. Only problem is that it shows me the regenerated password in the alert box. I want to echo it on the screen. how can I do that. Thanks Using jQuery fancybox and php

$.ajax({
    type: 'POST',
    url: '/processPassword.php',
    data: 'newPassword=' + password,
    success: function(success) {
        if(success == 1) {
            alert('The password has been reset. to: ' + password);
            location.href = 'mainpage.php';
        } else {
            alert('The password was not reset.');
        }
    }
});
});

function newPassword() {
        var password = "";
        some logic...
        return password;
}

Answer by RSolberg

Try this. Replace the “alert” call with the jQuery line below to set the HTML of a div…

HTML

<div id="newPass"></div>

jQuery

//this assumes that "password" has already been setup.
$("#newPass").html(password); 

I also would strongly advise you to consider having your PHP page generate the password and to use jQuery or something similar to request a PW to be built with server side code. Making the PW with client side code seems to be a huge security hole, almost like giving the blue prints of the prison to the prisoners…

Answer by Starx

This is something you could try

$.post {
   "processPassword.php",
   { newPassword: 'password' },
   function(data) {
       alert('Your new password is+'+data) ;
});

In this the data is the value echoed by the page processPassword.php not return so you must echo your new password in the end of page or somewhere.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!