|
-
Aug 2nd, 2006, 06:25 AM
#1
Thread Starter
Fanatic Member
how to pass information from PHP to JS, and from JS to PHP?
Hello guys,
I'm bulding a rich user interface, with a lot of javascript interaction (it creates rows in a table, cells, textboxes, select lists, buttons, etc) and on the onclick of the form submit, I'm calling a JS function that retrieves this information and stores it in a string in a hidden field, so PHP can retrieve the information on the server side and process it.
Is there a better way to achive this and is this considered bad programming practice??
And what about when I want to pass information from PHP to JS that's not visible to the normal user?
Thanks
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 2nd, 2006, 08:45 AM
#2
Addicted Member
Re: how to pass information from PHP to JS, and from JS to PHP?
PHP Code:
<script language="javascript" type="text/javascript">
var user_id = <?php echo($user_id); ?> ;
</script>
As for getting data from Javascript to PHP, I'm not entirely sure...
-
Aug 2nd, 2006, 08:52 AM
#3
Re: how to pass information from PHP to JS, and from JS to PHP?
 Originally Posted by HoraShadow
Is there a better way to achive this and is this considered bad programming practice??
What happens if the user has JS disabled?
-
Aug 2nd, 2006, 09:26 AM
#4
Thread Starter
Fanatic Member
Re: how to pass information from PHP to JS, and from JS to PHP?
Thanks for the replies guys.
@rabbit, I'm talking about a degree more advance than that. Not just echo'ing text.
@penagate, if the user has JS disabled, he can't use most of the pages, since they are JS intensive.
At the login screen it will check for JS enabled. If not request that they use a browser with javascript enabled and W3C standards.
This site it's not open to public, so there's not going to be "normal" users surfing.
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 2nd, 2006, 09:30 AM
#5
Re: how to pass information from PHP to JS, and from JS to PHP?
Ah, that's fine then.
I suggest you study "AJAX" and submit the form using that technique.
-
Aug 3rd, 2006, 05:26 AM
#6
Thread Starter
Fanatic Member
Re: how to pass information from PHP to JS, and from JS to PHP?
Thanks for the reply penagate.
I don't have time with my deadline to study ajax. I have to finish this for this monday.
Does my way of doing it sucks?
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 3rd, 2006, 06:02 AM
#7
Re: how to pass information from PHP to JS, and from JS to PHP?
Yes, but if you don't have time to learn something new it's fine 
But, it doesn't take four days to learn Ajax. You can have something up and running in about an hour, depending on how familiar you are with JS. It's basically just making a request from the JS code rather than submitting the form. One call to an XMLHttpRequest object and setting a listener for its completed event.
-
Aug 3rd, 2006, 03:50 PM
#8
Thread Starter
Fanatic Member
Re: how to pass information from PHP to JS, and from JS to PHP?
Yeah, I've been postponing both atlas and AJAX for quite a while now. :S
Thanks man
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 4th, 2006, 03:34 AM
#9
Thread Starter
Fanatic Member
Re: how to pass information from PHP to JS, and from JS to PHP?
Ok penagate, you convinced me and I'm learning AJAX.
Thanks bro!
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 4th, 2006, 03:59 AM
#10
Re: how to pass information from PHP to JS, and from JS to PHP?
That's the spirit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|