Help please with inputting and then passing parameters

E

Eric Johnston

I want the visitor to enter three numbers on the page and then click a
button "generate image" which will I hope cause a generated gif image to be
displayed alongside on the page.

This involved a php page elsewhere which does all the computing of the gif
image. I can make this work successfully by using a static call like:
<img src="test12.php?a=15&b=65&c=33000" width="200" height="200">

How do I write javascript to allow the visitor to enter 3 numbers and, when
ready, click a button to send a request to calculate
test12.php?a=15&b=65&c=33000 and display the new gif on the same page,
ideally with the option to edits the numbers and click again for different
image ?

Best regards, Eric.
 
L

Lee

Eric Johnston said:
I want the visitor to enter three numbers on the page and then click a
button "generate image" which will I hope cause a generated gif image to be
displayed alongside on the page.

This involved a php page elsewhere which does all the computing of the gif
image. I can make this work successfully by using a static call like:
<img src="test12.php?a=15&b=65&c=33000" width="200" height="200">

How do I write javascript to allow the visitor to enter 3 numbers and, when
ready, click a button to send a request to calculate
test12.php?a=15&b=65&c=33000 and display the new gif on the same page,
ideally with the option to edits the numbers and click again for different
image ?

You don't really want to use Javascript for that. You want to learn
about form processing in PHP. This isn't the correct newsgroup for that.
 
E

Eric Johnston

Lee said:
Eric Johnston said:

You don't really want to use Javascript for that. You want to learn
about form processing in PHP. This isn't the correct newsgroup for
that.

Many thanks Danny and Lee

I am not attempting validation at this stage.
I have just made an html form and elements. The three numbers come in OK
( I can multiply them etc and display a total for example) but can't output
the three number variables as url link parameters:
This does not work:
document.write('<img
src="test12.php?a=form.a.value&b=form.b.value&b=form.c.value" width="200"
height="200"></td>');
It just sends out the text names of the variables like
"test12.php?a=form.a.value etc", even when form.a.value=15

On the other hand this static experiment does work
//document.write('<img src="test12.php?a=15&b=25&c=33000" width="200"
height="200"></td>');
Unfortunately this deletes the existing browser page creates a blank brower
page with the new gif instead of putting the gif into the existing page.
Solving that will be the next problem after I've got the variables going
into the parameters.

Is it possible to avoid javascript ? Does some html command allow you to
put form variables on the end of a url link that will call a gif?

I've tried doing html form method=post and can successfully transfer all the
variables to the php page and process the data in the php, but the result is
to give control to the php page rather than simply getting the php page to
return only a gif file. I want the new gif to appear back on the original
page alongside the 3 input numbers to give the visitor a chance to review
the image and try other numbers.

At the moment I have two pages. An html page (with embedded javascript, if
needed) that displays the input number boxes and a php page that takes in
three numbers and return a gif. I want the gif back on the html input page
ready for another go. If my concept is wrong please say.

Best regards, Eric.
 
L

Lee

Eric Johnston said:
Many thanks Danny and Lee
At the moment I have two pages. An html page (with embedded javascript, if
needed) that displays the input number boxes and a php page that takes in
three numbers and return a gif. I want the gif back on the html input page
ready for another go. If my concept is wrong please say.

Your form should have the ACTION attribute set to the URL of
your PHP page. The PHP page can then receive the values directly
from the form, instead of from the URL. That's what PHP form
processing is all about.
 
E

Eric Johnston

Lee said:
Eric Johnston said:


Your form should have the ACTION attribute set to the URL of
your PHP page. The PHP page can then receive the values directly
from the form, instead of from the URL. That's what PHP form
processing is all about.

Yes, I have made the html action work OK, but doing that gives control to
the php page and I was wanting the php page to return only the gif which
would display itself in the original html page. If it is not possible to do
what I suggest with javascript I may try to use one big php page that keeps
reproducing itself each time the visitor enters new variables.

Thanks, Eric.
 
G

Grant Wagner

Eric Johnston said:
I want the visitor to enter three numbers on the page and then click a
button "generate image" which will I hope cause a generated gif image
to be displayed alongside on the page.

This involved a php page elsewhere which does all the computing of the
gif image. I can make this work successfully by using a static call
like:
<img src="test12.php?a=15&b=65&c=33000" width="200" height="200">

How do I write javascript to allow the visitor to enter 3 numbers and,
when ready, click a button to send a request to calculate
test12.php?a=15&b=65&c=33000 and display the new gif on the same page,
ideally with the option to edits the numbers and click again for
different image ?

<img src="blank.gif" name="myImage" width="200" height="200">
<form name="myForm" action="post" onsubmit="return false;">
<input type="text" name="a">
<input type="text" name="b">
<input type="text" name="c">
<input type="button" name="btn" value="Update image"
onclick="updateImage(this.form);">
<script type="text/javascript">
function updateImage(f)
{
var img;
if (f && (f = f.elements) &&
(img = document.images) &&
(img = img['myImage'])
{
img.src = 'test.php' +
'?a=' + f['a'].value +
'&b=' + f['b'].value +
'&c=' + f['c'].value;
}
}
</script>
</form>

Then test.php would use ImageMagick to do something like the following.
This is a shell script, but you could either get PHPMagick, or shell out
from PHP to invoke 'convert':

#!/usr/bin/sh
echo "Content-type: image/gif"
echo ""
# retrieve the values of a, b and c from
# $QUERY and calculate the $answer
/usr/local/bin/convert \
-background '#000000FF' -fill '#0000000' \
-pointsize 12 label:"$answer" \
gif:-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top