|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a javascript function that needs to be done with PHP because I have to take this result and use it in a SQL query Any ideas? So this generates a random number up to 4 digits long Then supplies it to the text field 'txt_PE_N' on screen. Is there a way to either do this in PHP or use javascript to write the PHP code to the file? Code:
function f_GeneratePE_N(x_range){
var rand01 = Math.floor(Math.random()* x_range);
document.frm_insert.txt_PE_N.value = rand01;
document.frm_insert.txt_PE_N2.value = "00";
}
I just started to learn Ajax so I am not quite here yet, Thanks.
__________________
~xim www.jfm411.com Last edited by xim : July 3rd, 2009 at 02:38 AM. |
|
#2
|
|||
|
|||
|
you can use mt_rand(min,max) to generate a random number. If you want to fill a text field with that number just put it in the value attribute.
PHP Code:
if you want to get the text field from javascript to php, you can put it as part of a form. Or if you already have a form that get posted, you could also use javascript to change the action attribute on the form to submitForm.php?num={num} |
|
#3
|
|||
|
|||
|
Thanks for that Llama!
There is one more issue though... I think I may have a solution so hear me out and then give me any advice you can... When the user comes to the form, they are presented with a empty field. Here they can use a previously used serial number (to UPDATE a record in the DB) or click a button to generate a new unique number (to INSERT a new record in the DB) Right now the form is set up as one form with the javascript function I mentioned earlier. What do you think of me making the "Generate New Number" button the only element in a separate form? Then it can send to itself, generate and query the random number and I will set the Code:
$_POST['serial_num'] in the text field's value property use Code:
if(var){echo}else{}
Then they can go through the rest of the form and the variable will already be there waiting. I also have a 2nd txt field nxt to the first one with an increment button done through javascript, but that should not have any bearing on the first field right? |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Is there a php solution to this javascript? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|