Forum Moderators: coopster

Message Too Old, No Replies

php and javascript

can javascript be used in php?

         

Doood

2:42 pm on Sep 1, 2008 (gmt 0)

10+ Year Member



Can the javascript output from a form also be used in php?

The user inputs info in the form and on submit it returns a special link code based on their input. I've got it set to display the link code twice on the page, one so they can copy it and the other I want to use to open an iframe on the page with that link code so they can see the changes. Problem is that the link code is not anywhere in the source of the page, it's only shown on the screen.

I know how to put php in javascript, but not javascript in php.

Is it possible to echo the form output in php?

penders

3:56 pm on Sep 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the output of the form to be processed by PHP, it needs to be posted back to the server. Alternatively you could use AJAX (XMLHttpRequest object) to get JavaScript to send the form data back to the server. Either way, it needs to get back to the server for PHP to do anything with it.

However, it sounds as if you could do what you are after with just JavaScript? Or just use PHP, and no JavaScript?

Doood

5:09 pm on Sep 1, 2008 (gmt 0)

10+ Year Member



Yeah it probably does need to redone in only php. I don't like javascript anyway.

It's just that the programmer who made other php scripts for me used javascript for the forms and I'm editing those scripts for something new.

penders

6:42 am on Sep 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...used javascript for the forms...

The programmer was perhaps trying to prevent form spam? However, for general accessibility it is probably better to use PHP and incorporate several 'spam traps'. A great discussion on form spam recently in the HTML forum [webmasterworld.com].

However, you could still create your IFRAME element with JavaScript, assign the SRC attribute to the link you have generated and append your IFRAME to the document/page?

Doood

6:15 pm on Sep 2, 2008 (gmt 0)

10+ Year Member



Those forms weren't for sending emails, they're all for webmasters to create link boxes after logging in.

I just changed to form over to all php and removed the javascript and it works exactly as I wanted. I think I'll stick with php from now on, it's so much easier and a lot nicer to look at too.