Web Design and Development Forums

Image button triggers <form> action

This is a discussion on "Image button triggers <form> action" within the JavaScript Forum section. This forum, and the thread "Image button triggers <form> action are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 17th, 2008, 16:17   #1 (permalink)
New Member
 
Join Date: May 2007
Location: Ohio
Posts: 3
Image button triggers <form> action

For learning purposes, I have written a very small; web, php & mysql based, Accounts Payable Voucher Entry page. The page has two parts.
1. Voucher Header Information
2. Accounting Distribution Lines (1 to n rows)

With the Accounting Distribution lines, I have added buttons to add a new row ("+") and to delete a row ("-"). It works when I do not have the <form> tag. When I add the <form> tag, my "+" button triggers the "action" property.

To add a row or delete a row, I have used javascript and jquery-1.2.1.js.

When the <form> tag is present, the following code always adds or deletes a row:
echo "<input type='button' value='del' class='delrow' id='delrow' width='65' image='images/btnDel20.gif'>";
echo "<input type='button' value='add' class='addrow' id='addrow' width='65' image='images/btnAdd20.gif'/>"

but the standard button is really ugly.

I designed my own image button, and uses this code:
echo " <input type='image' border='0' class='delrow' id='delrow' width='20' height='20' src='images/btnDelRow.png'> ";
echo " <input type='image' border='0' class='addrow' id='addrow' width='20' height='20' src='images/btnAddRow.png'> ";


This code only works with without the <form> tag. When I add a <form> tag, it triggers adds a row and then perform the "action" event.
<form action="vchrAddReg3.php">.

I did a screen capture video (6MB) and posted it on www.rapidshare.com.
It shows the image buttons not working and the standard buttons working. The <form> tag is present. Here is the link:
http://rapidshare.com/files/10800727...-FormError.avi

Here are three screen shots showing how the buttons look and work:
Initial display:

Add 3 rows:

Delete rows 2 & 3:




Question:
Is there a way to jazz up the standard button using this code?

echo "<input type='button' value='del' class='delrow' id='delrow'>";
echo "<input type='button' value='add' class='addrow' id='addrow'/>"


OR...

Is there a way to make this code Not trigger the <form action="vchrAddReg3.php"> using this code?
echo "<input type='button' value='del' class='delrow' id='delrow'>";

echo "<input type='button' value='add' class='addrow' id='addrow'/>";


Thank you very much for any input on how to jazz up the standard button or how to not trigger <form action="vchrAddReg3.php">!!!



Code Follows (two php programs)
vchrAddReg3.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<link href="images/ss.css" rel="stylesheet" type="text/css" />
<link href="images/ss.css1" rel="stylesheet" type="text/css" />
<link href="images/ss.css2" rel="stylesheet" type="text/css" />
div {
display:inline;
white-space:nowrap;
}
.page
{
width: 675px
}
div {
display:inline;
white-space:nowrap;
}
.table-borderz {
border-right-width: 2px;
border-left-width: 2px;
border-bottom-width: 2px;
border-top-width: 2px;
border-top-style: solid;
border-right-style: solid;
border-left-style: solid;
border-bottom-style: solid;
border-right-color: #D0B759;
border-left-color: #D0B759;
border-bottom-color: #D0B759;
border-top-color:#D0B759;
}
.blue-borderz {
background-color: white;
border-color: #CDD7DC;
border-style:solid;
border-width:2px;
}
</style>
<script type="text/javascript" src="./includes/jquery-1.2.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var cursorval = 1;
$("#main input.delrow:first").css({display: "none"});

$("#addrow").click(function() {
$.get("./newrow.php",{ cursor: cursorval }, function(data) {
$("#main").append(data);
});
cursorval += 1;
$(document).ajaxSuccess(function(){
$("#main input.delrow:first").css({display: "inline"});
$("#addrow").appendTo("#main div:last");

$("#main input.delrow").bind("click", function() {
if($("#main input.delrow").length == 1) {
$("#main input.delrow:first").css({display: "none"});
}
if($("#main input.delrow").index($(this)[0]) != ($("#main input.delrow").length-1)) {
$(this).parents("tr").remove();
}
else {
$("#addrow").appendTo($("#main div").get(($("div").length)-2));
$("#main input.delrow:last").parents("tr").remove();
}
});

});

});

});
</script>
</head>
<body>

<form action="vchrAddReg3.php"<?='?pass_var=$vndrNo|$fir stPass'?>" method="post" name="vchrAddReg3" id="vchrAddReg3">

<table id="main" width="700" height="75" border="6px" bordercolor="#D0B759" cellpadding="4" cellspacing="0" class="table-borderz">
<thead>
<tr align="left" bgcolor="#D0B759" bordercolor="#D0B759" height="25" halign="center" valign="middle" >
<th class="blck13b" colspan="7">Distribution Lines:</th>
</tr>
<tr align="left" class="blck13b" bgcolor="#CDD7DC" bordercolor="#CDD7DC" height="25" cellspacing="0" valign="middle">
<th width="46" >Line</th>
<th width="88">Bus Unit</th>
<th width="92">Account</th>
<th width="91">Project</th>
<th width="88">Task</th>
<th width="91">Amount</th>
<th width="130">&nbsp;</th>
</tr>
</thead>
<?php
echo "<tbody>";
echo "<tr>";
echo "<td width='46'>1</td>";
echo "<td width='88' align='left'><input name='bu1' type='text' size='5' class='blue-borderz'/>$bu1</td>";
echo "<td width='92' align='left'><input name='acct1' type='text' size='7' class='blue-borderz'/>$acct1</td>";
echo "<td width='91' align='left'><input name='proj1' type='text' size='7' class='blue-borderz'/>$proj</td>";
echo "<td width='88' align='left'><input name='task1' type='text' size='7' class='blue-borderz'/>$task1</td>";
echo "<td width='91' align='left'><input name='amt1' type='text' size='8' class='blue-borderz'/>$amt2</td>";
echo "<td width='130'><div>";
//echo " <input type='image' border='0' class='delrow' id='delrow' width='20' height='20' src='images/btnDel-1.png'> ";
//echo " <input type='image' border='0' class='addrow' id='addrow' width='20' height='20' src='images/btnAdd-1.png'> ";
echo "<input type='button' value='del' class='delrow' id='delrow' width='65' image='images/btnDel20.gif'>";
echo "<input type='button' value='add' class='addrow' id='addrow' width='65' image='images/btnAdd20.gif'/></div>";
echo "</td></tr>";
echo "</tbody>";
?>
</table>
</form>
</body>
</html>


newrow.php
<?php
$cursor = $_GET['cursor'] + 1;

echo "<tr>";
echo "<td width='46' size='5' >$cursor</td>";
echo "<td width='88'><input name='javascript:bu{$cursor}' type='text' size='5' class='blue-borderz'/></td>";
echo "<td width='92'><input name='acct{$cursor}' type='text' size='7' class='blue-borderz'/></td>";
echo "<td width='91'><input name='proj{$cursor}' type='text' size='7' class='blue-borderz'/></td>";
echo "<td width='88'><input name='task{$cursor}' type='text' size='7' class='blue-borderz'/></td>";
echo "<td width='91'><input name='amt{$cursor}' type='text' size='8' class='blue-borderz'/></td>";
echo "<td size='130'><div>";
echo " <input type='image' border='0' class='delrow' id='delrow' width='20' height='20' src='images/btnDel.png'> ";
//echo "<input type='button' value='del' class='delrow' width='65'/>";
echo "</div>";
echo "</td></tr>";
?>


rcflyer2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 07:21   #2 (permalink)
New Member
 
Join Date: May 2007
Location: Ohio
Posts: 3
Re: Image button triggers <form> action

After searching the web, I found a site that will make css based buttons online. I noticed they used the style attribute/property.

I incorporated that into my <input type="button"...> tag and the javascript was executed and the <form action="vndrAddReg3.php" was not executed.

Problem solved.

Here are the working buttons:

<input type='button' value='-' class='delrow' id='delrow' style='text-align:center; background:#E7F0F5; border:#CDD7DC 2px solid; padding:1px; color:#000000; font-family:tahoma; font-size:10px; font-weight:900; height:20px;width:20px;'/>

<input type='button' value='+' class='addrow' id='addrow' style='text-align:center; background:#E7F0F5; border:#CDD7DC 2px solid; padding:1px; font-family:tahoma; font-size:13px; font-weight:900; height:20px; width:20px;'/>
rcflyer2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
preserve the back button action when doing AJAX calls pesho318i JavaScript Forum 2 Nov 28th, 2007 12:37
how to change button action into a movieclip button action cjrollo Flash & Multimedia Forum 7 Nov 21st, 2007 17:07
BUTTON will not take an action script griffonwing Flash & Multimedia Forum 2 Jun 8th, 2007 12:33
MouseOver for Form Submit Button image? masonbarge JavaScript Forum 4 Oct 31st, 2006 11:58
Condition on button action artdog Flash & Multimedia Forum 1 Sep 14th, 2006 19:45



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 11:44.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59