0

I have input fields, which I process with AJAX and send it on another file. The value of the inputs is always different. How in the file, where I get the data from AJAX, to change the variable id always when I get the data from AJAX.

Example: I get the data from AJAX in this file:

<?php
$id=1;
echo '<div id="$id"></div>';
?>

Then I display the result in the page with AJAX.

I want the id of the div to be always different.
2
  • 1
    An id attribute MUST start with a letter, some browsers will have problems with numeric ids. Commented Mar 10, 2010 at 13:58
  • Thank you ,too ,that is very important! I can add letters before the id. Commented Mar 10, 2010 at 14:21

2 Answers 2

1

if you want $id a random number use the function randlink text

$id=rand(0,100); // random between 0 and 100, 0 and 100 incluse

you can also create a random string

function genRandomString($length) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[rand(0, strlen($characters))];
    }
    return $string;
}
Sign up to request clarification or add additional context in comments.

Comments

0

One can create different random number through time checking, this will create random number on the basis of time and will generate different number each microseconds.

//this will add a char on the beginning of the value so it do not start with numeral

$str=range(a,z);

//using date function for generating random number

$i= $str[rand(0,25)].date('Ymzhisu');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.