PDA

View Full Version : Get image param value


tom123
03-27-2006, 12:56 PM
Ive got the following javascript and html. The js changes the image when a image is clicked. Problem is how do i retreive the image value when the form is submitted.


function change_order(image1)
{
if (!image1.tog){
image1.tog = true;
image1.src = "/Images/movedown.png";
}
else{
image1.tog = false;
image1.src = "/Images/moveup.png";
}
return;
}

<form action="summarise.cgi" name="sorting" method="post" align="right">
<table align="center">
<tr>
<td align="center"><i><u>Sort fields:</u></i></td>
<td align="center"><i><u>Order:</u></i></td>
</tr>
<tr>
<td><b>1. </b>
<select name="possible_sorts_1" class="selectBox" onchange="add_sort_1()">
<option value=""></option>
<tmpl_loop name="possible_sorts">
<option value="<tmpl_var pos_sort>"><tmpl_var pos_sort></option>
</tmpl_loop>
</select>
</td>
<td>
<img name="image1" src="<tmpl_var order_1>" onclick="change_order(this)" value="tmpl_var order_1"/>
</td>
</tr>
<tr>
<td align="right"><input name="confirm" type="image" src="/Project/Images/confirm.png" alt="confirm" value="confirm" valign="top"/>
</td>
</tr>
</table>
</form>

The following summarise.cgi code wont get the image value

# get previous page
$prev_page= $ENV{"HTTP_REFERER"};
($name,$path,$suffix) = fileparse($prev_page,@suffixlist);
$page = $name;

# get parameters and set session variables if coming from sorting.cgi
if ($page =~ /sorting.cgi/){

# Create button object
$button = new CGI;

print param('image1');
# Check if user selected the confirm button, before proceding
if ($button->param('confirm')){
print param('image1');
}
}

FishMonger
03-27-2006, 04:54 PM
The name and value are not valid attributes of the image tag, so nothing gets sent back to the script. You need to use an input tag and specify type="image"

http://www.w3schools.com/tags/tag_input.asp
http://www.w3schools.com/tags/tag_img.asp

KevinADC
03-28-2006, 07:32 AM
The name attribute is valid:

http://www.blooberry.com/indexdot/html/tagpages/i/image.htm

although it does depend on the DTD being used. The value attribute is not valid however. You could try adding a hidden (or even visible) form field and populating it with the value of the image name using javascript before the form data is submitted.

Another alternative is to make the img a link and use the query string to send the data back to the script.

<a href="cgi-bin/scriptname.cgi?name=frog.jpg"><img src="frog.jpg"></a>