Jump to content

Form with dynamic action


Darkmatter5

Recommended Posts

Here's my js

<script type="text/javascript" src="<?php echo "$url/library/scripts/selectclass.js"; ?>" /></script>
<script type="text/javascript" />
function subit(which) {
    if(which=='reroll') { document.attributes.action="res_t-pcb2.php?roll=yes"; }
    else if(which=='attributes') { document.attributes.action="tools/scripts/pcb.php"; }
}
</script>

 

Here's my html

<form method="get" name="attributes">
    <input type="hidden" name="page" value="2">
    <table>
      <tr>
        <td align="right"><label for="abil_str">Str: </label></td>
        <td><input type="text" name="abil_str" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='strength'"),0,50); ?></td>
      </tr>
      <tr>
        <td align="right"><label for="abil_dex">Dex: </label></td>
        <td><input type="text" name="abil_dex" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='dexterity'"),0,50); ?></td>
      </tr>
      <tr>
        <td align="right"><label for="abil_dex">Con: </label></td>
        <td><input type="text" name="abil_con" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='constitution'"),0,50); ?></td>
      </tr>
      <tr>
        <td align="right"><label for="abil_dex">Int: </label></td>
        <td><input type="text" name="abil_int" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='intelligence'"),0,50); ?></td>
      </tr>
      <tr>
        <td align="right"><label for="abil_dex">Wis: </label></td>
        <td><input type="text" name="abil_wis" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='wisdom'"),0,50); ?></td>
      </tr>
      <tr>
        <td align="right"><label for="abil_dex">Cha: </label></td>
        <td><input type="text" name="abil_cha" size="2" value="<?php if($_GET['roll']=='yes') { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='charisma'"),0,50); ?></td>
      </tr>
      <tr><td colspan="2" align="center"><input type="submit" name="reroll" value="Reroll" onclick="javascript:subit(reroll);"> <input type="submit" name="submit" value="Submit" onclick="javascript:subit(attributes);"></td></tr>
    </table>
    </form>

 

When either submit button is pressed the following is sent to the browser.

"res_t-pcb_p2.php?page=2&abil_str=&abil_dex=&abil_con=&abil_int=&abil_wis=&abil_cha=&reroll=Reroll"

"res_t-pcb_p2.php?page=2&abil_str=&abil_dex=&abil_con=&abil_int=&abil_wis=&abil_cha=&submit=Submit"

 

If reroll is pressed it should set the form action to "res_t-pcb2.php?roll=yes". If submit is pressed it should set the form action to "tools/scripts/pcb.php".

What's wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.