PDA

View Full Version : PHP with JavaScript work around?


V@no.
05-24-2003, 11:20 PM
Hi! that's me again, with some wierdo questions :rolleyes: :D
I have asked before simular question, but I think it's better ask again with less confusing information ;)
so, here it goes:

I'm trying combine PHP and JavaScript work together interactivly. Yes, I know those two languages are work differently and cant be put under same line, but I already succeed with one task, I can use JavaScript to send back to the server users actions and receive the result without page refreshing, by using <img src="">
for example, http://come.no-ip.com click at "Album" button under images. It will execute .php file, add the image into database, and incase it was successfull return new image location in header('Location: newimage.gif');.
it done by using:
onClick="this.src='script.php';"
so, it works well with images...now, how about for example dropdown form?
how can I tell JS to execute a .php file? when I change option? or if I click a button, without refreshing whole page?

does it make any sence?

thx for any info ;)

cpradio
05-25-2003, 02:37 AM
Well you have almost answered this entirely yourself unknowingly.

Make an image next to the drop down list like so:
<img name="dropdownphp" src="spacer.gif" width="1px" height="1px">

Then have your drop down list like so:
<select onchange"document.body.dropdownphp.src='this.value;'" size="1">
<option value="path to php script">Option 1</option>
....
</select>


-Matt

V@no.
05-25-2003, 02:54 AM
great! good idea, but...how can I check the return? I mean, if it was success or not?
for example, if I want disable the select option if it was success? like, by checking the source of the image? is thats the way?

P.S. I think I posted under wrong forum, didnt I?...well, @moderators: feel free to move it to the right place :D

cpradio
05-25-2003, 02:58 AM
Well you can do that inside the PHP script that is called from the drop down menu:


echo "<script type=\"text/javascript\">\n" .
"document.body.form.name of drop down menu.disable = disable;\n" .
"</script>\n";


However if you do this you cant change use header();

-Matt

V@no.
05-25-2003, 03:01 AM
but that's way I'm gonna get 404 error in the server's log for the image...

cpradio
05-25-2003, 03:04 AM
How about:

echo "<script type=\"text/javascript\">\n" .
"document.body.form.name of drop down menu.disable = disable;\n" .
"self.location='path to image';\n" .
"</script>\n";

V@no.
05-25-2003, 03:44 AM
unfortunetly it didnt work..it does execute the .php file, but the picture gets 404 error and also, it doesnt disable <select>...
I have tryed use something like:
<select name=\"dropdown\" onchange=\"document.write('<script src=\'1.php?action=print\'><\/script>');\">it worked...almost, but it erase whole page...why does it do that? I thought it should just add an extra "text" to the opened page, but not start new one...