PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 3rd, 2009, 02:33 AM
xim xim is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Franklin, MA USA
Posts: 33 xim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 59 sec
Reputation Power: 3
Question Is there a php solution to this javascript?

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.

Reply With Quote
  #2  
Old July 3rd, 2009, 04:10 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
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:
<?php
$num 
mt_rand(1000,9999); //generate a random number from 1000 to 9999 (4 digits)
echo "<input type='text' name='txt_PE_N' value='$num' />";
?>

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}

Reply With Quote
  #3  
Old July 3rd, 2009, 04:30 AM
xim xim is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Franklin, MA USA
Posts: 33 xim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 59 sec
Reputation Power: 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']
variable there.
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?

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Is there a php solution to this javascript?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek