javascript - PHP: onClick not working - Stack Overflow
My button "VIEW" is not going to the form of "booking_content.php" instead its just refreshing the page of "home.php"
Here's my code:
$radio = mysql_query("SELECT fldBldgName, MAX(fldTotalDuration) as fldTotalDuration FROM tbldata WHERE fldNetname = '".$get_radio."' AND fldMonth = '".$get_month."' AND fldWeek = '".$get_week. "' GROUP BY fldBldgName ORDER BY id, fldBldgName, fldTotalDuration DESC");
echo "<table class = 'tblMain'>";
echo "<tr align='left'>";
echo "<td><b><u>BUILDING NAME</u></b></td>";
while ($row = mysql_fetch_array($radio))
{
echo "<tr><td align='left'>";
echo $row['fldBldgName']."'>";
echo "<input type='image' src='image/view.png' name='viewBldg' onClick='this.form.action='booking_content.php'; this.form.submit()'>";
echo $row['fldBldgName'];
}
echo "</tr></table>";
My problem is this one:
echo "<input type='image' src='image/view.png' name='viewBldg' onClick='this.form.action='booking_content.php'; this.form.submit()'>";
*The onClick is not going to the page of booking_content.php instead its just refreshing the page...
I can't upload an example result of my program...
Please click this link so you can view my sample program: /
ALSO the code for my button is inside of a fieldset...
My button "VIEW" is not going to the form of "booking_content.php" instead its just refreshing the page of "home.php"
Here's my code:
$radio = mysql_query("SELECT fldBldgName, MAX(fldTotalDuration) as fldTotalDuration FROM tbldata WHERE fldNetname = '".$get_radio."' AND fldMonth = '".$get_month."' AND fldWeek = '".$get_week. "' GROUP BY fldBldgName ORDER BY id, fldBldgName, fldTotalDuration DESC");
echo "<table class = 'tblMain'>";
echo "<tr align='left'>";
echo "<td><b><u>BUILDING NAME</u></b></td>";
while ($row = mysql_fetch_array($radio))
{
echo "<tr><td align='left'>";
echo $row['fldBldgName']."'>";
echo "<input type='image' src='image/view.png' name='viewBldg' onClick='this.form.action='booking_content.php'; this.form.submit()'>";
echo $row['fldBldgName'];
}
echo "</tr></table>";
My problem is this one:
echo "<input type='image' src='image/view.png' name='viewBldg' onClick='this.form.action='booking_content.php'; this.form.submit()'>";
*The onClick is not going to the page of booking_content.php instead its just refreshing the page...
I can't upload an example result of my program...
Please click this link so you can view my sample program: http://postimg/image/wbiigechn/
ALSO the code for my button is inside of a fieldset...
Share Improve this question edited Sep 7, 2013 at 14:06 ComFreek 29.5k18 gold badges107 silver badges157 bronze badges asked Sep 7, 2013 at 13:43 Princess ToledoPrincess Toledo 811 gold badge3 silver badges11 bronze badges 2- Where is the form tag in your code? – SaidbakR Commented Sep 7, 2013 at 13:52
- @sємsєм..its in the upper part of my home.php...I didn't include it in the question...but heres the form... <form name='form' method='post' action="">, the code is inside of the form... – Princess Toledo Commented Sep 7, 2013 at 13:54
2 Answers
Reset to default 3Your attempt will generate the following HTML:
<input type='image' src='image/view.png' name='viewBldg'
onclick='this.form.action='booking_content.php'; this.form.submit()'>
So your browser wont be able to interpret the onclick attribute correctly, because the '
before booking_content
.
Try the following:
echo "<input type='image' src='image/view.png' name='viewBldg'
onclick=\"this.form.action='booking_content.php'; this.form.submit()\">";
Which should generate a valid HTML such as:
<input type='image' src='image/view.png' name='viewBldg'
onclick="this.form.action='booking_content.php'; this.form.submit()">
You tried to access your form in wrong way. this
in your code refer to the input itself not to the form.
You may have to do something like the following:
<input type="button" value="view" onclick="document.fn.action='http://google.';document.fn.submit();" />
where fn the attribute name
value of your form
.
Notice: in this case you should have only one form with that name.
Check out this demo: http://jsbin./asekAqu/1 or its sample code: http://jsbin./asekAqu/1/edit
- 人工智能的温度:AI究竟会带给我们怎样的世界?
- 软件定义:英特尔携VMware重塑数据中心
- 微信支付和支付宝口水战开打!
- Mac电脑与PC九大区别
- Can I Trigger Console Application From Window Service in Visual Studio c#? - Stack Overflow
- Spring Boot 3: Exclude REST Endpoints from Authorization - Stack Overflow
- dataframe - Dataset uploaded and verified, but cannot use read.csv - Stack Overflow
- responsive design - How achieve given UI using custom clipper in flutter - Stack Overflow
- postgresql - How to use prisma updateManyupsert in order to update multiple data with one database query? - Stack Overflow
- amazon web services - How to create a CloudWatch alarm for an EventBridge Pipe's stopped state in AWS? - Stack Overflow
- kotlin - Do I need Serialization to Transfer a MutableMap Between Minecraft Server and Client? If so, How Should I Serialize It?
- Flutter GoRouter: ShellRoute with Subroutes - Stack Overflow
- c# - System.Printing.PrintJobException: 'An exception occurred while setting the print job. Win32 error: The parameter i
- laravel - Customizing Fortify for Multi-Tenant Password Resets Tokens with Domain-Specific Tokens - Stack Overflow
- combinatorics - MiniZinc - Optimizing Script for Scheduling Problem - Stack Overflow
- wordpress - XML Reader Not Found in cPANEL php v8.3 - Stack Overflow
- python - preprocessing strategies for OCR (pytesseract) character recognition - Stack Overflow