1

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.org/image/wbiigechn/

ALSO the code for my button is inside of a fieldset...

2
  • Where is the form tag in your code? 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... Commented Sep 7, 2013 at 13:54

2 Answers 2

3

Your 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()">
Sign up to request clarification or add additional context in comments.

8 Comments

Can you paste the output generated by PHP? (just the onclick part)
@RienNeVaPlus...what do you mean about the just onclick part? do u mean the code of booking_content.php??
I've updated my answer. Whats PHP returing on your HTML page? It should look something like <input ... onclick='this.form.action="booking_content.php"; this.form.submit()'>
@RienNeVaPlus...I tried to put it without using echo and make it html code..its working but when I put it inside of <?php ?> its not working already... I tried your code but still the same, not working.. :(
No, the problem is just a mix of ' and " which leads to malformated HTML. Can you please copy & paste the output source of your PHP script?
|
0

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.com';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.com/asekAqu/1 or its sample code: http://jsbin.com/asekAqu/1/edit

1 Comment

this.form in the event handler of an input inside a form will always reference the surrounding form.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.