DS928
asked on
Replace Submit button with an image
I have a submit button that works perfectly, it is calling a php file. I want to pretty up the site and use an image instead. This works (No Image)
This doesn't, with image.
It sounds easy enough, but I've been reading that replacing a submit button with an image isn't that easy if your using or rather calling a php form. Still haven't found a working solution.
<input type="submit" value="Show Me The Results!" name="select">
This doesn't, with image.
<input type="image" name="select" src="../PaleSearch.jpg" style="border:0;" />
It sounds easy enough, but I've been reading that replacing a submit button with an image isn't that easy if your using or rather calling a php form. Still haven't found a working solution.
ASKER
This is the link. its suppose to open a results page. It just sits there.
http://www.menuhead.net/Steelers/sections_demo.php
Thank you.
I put both buttons up. Click on place then across the three listboxes. Then show me the results.
I tried this link and that did not work either, but he explains a lot.
http://www.suburban-glory.com/blog?page=140
and this....
http://davidwalsh.name/php-form-submission-recognize-image-input-buttons
Trying this and it's not helping...
And on the form...
http://www.menuhead.net/Steelers/sections_demo.php
Thank you.
I put both buttons up. Click on place then across the three listboxes. Then show me the results.
I tried this link and that did not work either, but he explains a lot.
http://www.suburban-glory.com/blog?page=140
and this....
http://davidwalsh.name/php-form-submission-recognize-image-input-buttons
Trying this and it's not helping...
document.Animals.action ="result_place.php";
<?php
if (isset($_POST['select_x'])){
if ((@$_POST['select'] == 'x'))
{
echo "OK";exit;
}
else
{
echo "NOT";
}
}
?>
And on the form...
<input name="select" type="image" src="../GreySearch.jpg" value="x" >
ASKER
OK I found this code for this situation. The problem is that if I put it into my code it affects the other "image buttons" that have nothing to do with this. When I say affect, I mean nothing works, no response.
if (isset($_POST['select_x']) &&
isset($_POST['select_y'])) {
printf('<h1> You clicked on the following coordinates: x-$s, y-$s</h1>',
htmlspecialchars($_POST['select_x']),
htmlspecialchars($_POST['select_y'])
);
}else{
?>
<form method="post" action="<?php //echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="image" name="select" src="GreySearch.jpg"/>
</form>
<?php
}?>
What are you trying to do? are you trying to update the page while keeping the other buttons?
The following works without any problem:
Let me know what is going on EXACTLY if you still have a problem, you should post more code to make things more clear.
The following works without any problem:
// file.php:
<?php
if (isset($_POST['select_x']) &&
isset($_POST['select_y'])) {
$x = $_POST['select_x'];
$y = $_POST['select_y'];
echo("<h1> You clicked on the following coordinates: x-$x, y-$y</h1>");
}else{
?>
<form method="post" action="<?php //echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="image" name="select" src="GreySearch.jpg"/>
</form>
<?php
}?>
Let me know what is going on EXACTLY if you still have a problem, you should post more code to make things more clear.
Seems to work for me, I'm not sure if you've been working on it or not, though. What I did is simply modify the page live by using the Firebug console in Firefox... here's roughly what I did (hopefully in the correct order):
After doing this, it seemed to work just like it did with the old button.
$("input.button3").parent().attr("id", "xxx"); // give parent object of button an ID
var myButton = $("input.button3").clone(); // clone the button so we can change it
$("input.button3").remove(); // delete the button (can't change type on an existing object)
myButton.attr("type", "image"); // change cloned button to have type="image"
myButton.attr("src", "../PaleSearch.jpg"); // set source image
my Button.removeClass("button3"); // remove styling from old button
$("#xxx").append(myButton); // put cloned button where old button was
After doing this, it seemed to work just like it did with the old button.
ASKER
OK I get the part about x and y. I'm still foggy about how to use it. (The orange button you see is one I did in CSS) What I have is a switch that launches one of five different php pages depending on which image is selected, Place, Cuisine, etc.
The button code.....
The function.
You see if have the "x y" part rem out. I am not completely sure where to place it. Perhaps that is where the confusion now lies. Do I place it in the form or in the function? Is it before or after the page is called? Thank you.
The button code.....
<form name="Animals" method="post" onsubmit="return OnSubmitForm();">
<input type="image" name="select" img src="../GreySearch.jpg" width="160" height="30" /> </p>
The function.
function OnSubmitForm() {
var g = $("#Glass").val();
switch(g)
{
case "Place":
//alert("Glass = " + g);
document.Animals.action ="result_place.php";
//<?php
//if (isset($_POST['select_x']) &&
//isset($_POST['select_y'])) {
//printf('<h1> You clicked at the following coordinates: x-$s, y-$s</h1>',
//htmlspecialchars($_POST['select_x']),
//htmlspecialchars($_POST['select_y'])
//);
//}else{
//?>
//<form method="post" action="<?php //echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
//<input type="image" name="select" src="GreySearch.jpg"/>
//</form>
//<?php
//}?>
break;
case "Cuisine":
//alert("Glass = " + g);
document.Animals.action ="result_cuisine.php";
break;
case "City":
//alert("Glass = " + g);
document.Animals.action ="result_city.php";
break;
case "State":
//alert("Glass = " + g);
document.Animals.action ="result_state.php";
break;
case "ZipCode":
//alert("Glass = " + g);
document.Animals.action ="result_zip.php";
break;
}
}
You see if have the "x y" part rem out. I am not completely sure where to place it. Perhaps that is where the confusion now lies. Do I place it in the form or in the function? Is it before or after the page is called? Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, Ray.
Thanks for the points and thanks for using EE! ~Ray