JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

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 Dev Shed Forums Sponsor:
  #1  
Old May 20th, 2001, 02:25 PM
ds99jove ds99jove is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 37 ds99jove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
PHP and Javascript Combined

Hi,

I'm working on a Javascript to update 2 listboxes with values, here's where PHP come in. I use PHP to get the values from a Database, but how can I use Javascript variables in PHP code?
What I'm trying to do looks something like this simplified:

<SCRIPT LANGUAGE="Javascript">
function getPerioder(selection)
{
var ftgID = selection.options[selection.selectedIndex].value;
<?php $result2=mysql_query("SELECT * FROM FtgPerioder WHERE ftgID=ftgID");
$object=mysql_fetch_object($result2);
$name=$object->name;
?>
document.form1.perioder.options[0].text=name;
}
</SCRIPT>


The thing I want to do is:
replace ftgID in
mysql_query("SELECT * FROM FtgPerioder WHERE ID=ftgID");
with the javascript variable

Help Greatly needed!
Many Thanks!
Jonas Versén

Last edited by ds99jove : May 20th, 2001 at 05:42 PM.

Reply With Quote
  #2  
Old May 20th, 2001, 07:22 PM
ds99jove ds99jove is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 37 ds99jove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Question Help needed bad!

I guess what I really want is to be able to access the Document Object Model from within PHP. If this is not possible, then someone please tell me how to:

Have 2 listboxes
Listbox nr 1 gets its values from a Database
Listbox nr 2 is dependent on Listbox nr 1 and gets its values from a database.

Reply With Quote
  #3  
Old May 20th, 2001, 07:28 PM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 757 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 32 sec
Reputation Power: 14
You can not pass the javascript variable to PHP clientside, ie without a refresh.

the other option is to load all possible results into javascript arays, but this could be a hefty file depending on the number of possible options, but that is your only other choice if you want to do this clientside.
__________________
resistance is no longer futile :: 423

Reply With Quote
  #4  
Old May 20th, 2001, 07:30 PM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 757 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 32 sec
Reputation Power: 14
actually - you could use forms in hidden frames etc. Need to know your javascript for that one though.

Reply With Quote
  #5  
Old May 21st, 2001, 03:56 AM
ds99jove ds99jove is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 37 ds99jove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Hi, thanks for the reply!

Before I went to sleep last night I too reached the conclusion that storing everything in a javascript array right away was a possible solution. The number of objects should not pass ~150. That should not drop performance too much should it?

About submitting the values, is there anyway of submitting a form without a submit button? Cause if the users have to click a submit button then I'm at the point that I'm specifically try to avoid

(ie. The user selects value 2 from Listbox 1, then clicks the submit button and selects value C from lisbox 2... then he goes back and changes listbox 1 to value 1 and saves. Problem here is that value 1 do not have the value C and voila! A bug is created!)

A simple solution would be something like:
..... onChange="refresh();">

but would that make the form values global values as submitting the form does? And is there a refresh() function?

Many Thanks Again!
Jonas Versén

Reply With Quote
  #6  
Old May 21st, 2001, 04:27 AM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 757 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 32 sec
Reputation Power: 14
You could can submit via (something like ) onchange="do_submit();"

function do_submit(){
var yak=document.formname.fieldname.selectedIndex;
document.formname.action=this.php?id=yak;
document.formname.submit();
}

my javcascript is not that hot but something like that should work.

Reply With Quote
  #7  
Old May 21st, 2001, 04:38 AM
ds99jove ds99jove is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 37 ds99jove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Great!!

Thanks!

Actually I only needed the:
document.formname.submit();
statement, since all the values I need are inside the form and the form has "METHOD='Post'" they are made global HTML variables I can access with PHP when the form is submitted, my problem was how to submit the form without the use of a button Now I've learned you can do that 2 using the DOM =)
I'll check back later if (when there are any more troubles!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > PHP and Javascript Combined

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap