Dynamic Actions for a form

  • Pop-Eye
  • Newbie
  • Newbie
  • Pop-Eye
  • Posts: 5

Post 3+ Months Ago

Trying to load different pages when different images are clicked. I have the following which does not work:
Code: [ Select ]
<form>
<input type='image' src='./img/pic1.jpg' onclick="this.form.action.value='xyz.php';this.form.submit();">
<input type='image' src='./img/pic2.jpg' onclick="this.form.action.value='abc.php';this.form.submit();">
</form>
  1. <form>
  2. <input type='image' src='./img/pic1.jpg' onclick="this.form.action.value='xyz.php';this.form.submit();">
  3. <input type='image' src='./img/pic2.jpg' onclick="this.form.action.value='abc.php';this.form.submit();">
  4. </form>


Any help will be appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

Just remove the ".value".

Code: [ Select ]
<form method="post">
<input type='image' src='./img/pic1.jpg' onclick="this.form.action='xyz.php';this.form.submit();">
<input type='image' src='./img/pic2.jpg' onclick="this.form.action='abc.php';this.form.submit();">
</form>
  1. <form method="post">
  2. <input type='image' src='./img/pic1.jpg' onclick="this.form.action='xyz.php';this.form.submit();">
  3. <input type='image' src='./img/pic2.jpg' onclick="this.form.action='abc.php';this.form.submit();">
  4. </form>


I added method="post" so it didn't show the x & y vars while submitting the form via GET instead of POST.
  • Pop-Eye
  • Newbie
  • Newbie
  • Pop-Eye
  • Posts: 5

Post 3+ Months Ago

Thanks for the reply. It worked fine. :P
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

Something must be wrong with your code then. The following is an example HTML 5 file, the first loads "xyz.php", the second loads "abc.php". I used alt="" tags, as I do not have your pictures.

Code: [ Select ]
<!DOCTYPE html>
<html lang="en-us" dir="ltr">
<head>
</head>
<body>

 <form method="post">
 <input type='image' alt="XYZ" src='./img/pic1.jpg' onclick="this.form.action='xyz.php';this.form.submit();">
 <input type='image' alt="ABC" src='./img/pic2.jpg' onclick="this.form.action='abc.php';this.form.submit();">
 </form>

</body>
</html>
  1. <!DOCTYPE html>
  2. <html lang="en-us" dir="ltr">
  3. <head>
  4. </head>
  5. <body>
  6.  <form method="post">
  7.  <input type='image' alt="XYZ" src='./img/pic1.jpg' onclick="this.form.action='xyz.php';this.form.submit();">
  8.  <input type='image' alt="ABC" src='./img/pic2.jpg' onclick="this.form.action='abc.php';this.form.submit();">
  9.  </form>
  10. </body>
  11. </html>

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 47 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.