Page 1 of 1

change from action URL on-the-fly

Posted: Tue Jan 20, 2009 10:25 am
by potato_chip
Hey, I want to change a form action url based on user input, and I used hyperlink to submit a form (since I have lots of rows like this and each has different values passed to javascript select_claim() function.). But it doesn't work! I have very simple php code here, but the it is the javascript problem. Can anyone help? Thanks very much!

Code: Select all

 
<form action="" method="post" name="smForm" id="smForm">
<table>
<tr>
        <td><a href="" onclick="select_claim('<?=$claimNumber?>', '<?=$suffix?>', '<?=$claimDiag1?>', '<?=$claimDiag2?>', '<?=$claimClass?>', '<?=$claimProvider?>'); return getclaim('myclaimForm'); " title="view claim detail"><?=$claimNumber?></a></td>
</tr></table>
<input type="hidden" name="claimNumber" id="claimNumber" value="<?=$claimNumber?>" />
<input type="hidden" name="suffix" id="suffix" value="<?=$selectedSuffix?>" />
<input type="hidden" name="claimDiag1" id="claimDiag1" value="<?=$claimDiag1?>" />
<input type="hidden" name="claimDiag2" id="claimDiag2" value="<?=$claimDiag2?>" />
<input type="hidden" name="claimClass" id="claimClass" value="<?=$claimClass?>" />
<input type="hidden" name="providerName" id="providerName" value="<?=$providerName?>" />
</form>
<script language="Javascript">
<!--
    function select_claim(claimnumber, suffix, claimdiag1, claimdiag2, claimclass, providername)
{
    getSection('claimNumber').value = claimnumber;
    getSection('suffix').value = suffix;
    getSection('claimDiag1').value = claimdiag1;
    getSection('claimDiag2').value = claimdiag2;
    getSection('claimClass').value = claimclass;
    getSection('providerName').value = providername;
}
function getclaim(formName)
{
    if(getSection('claimClass').value == 'M')
        document.forms[formName].action = 'claimDetailMed.php';
    else if(getSection('claimClass').value == 'D')
        document.forms[formName].action = 'claimDetailDen.php';
    else if(getSection('claimClass').value == 'V')
        document.forms[formName].action = 'claimDetailVis.php';
    else(getSection('claimClass').value == 'P')
        document.forms[formName].action = 'claimDetailPha.php';
    document.forms[formName].submit();  
    return true;
    }
}
 
//-->
</script>
 

Re: change from action URL on-the-fly

Posted: Tue Jan 20, 2009 10:35 am
by Burrito

Code: Select all

 
fm = document.getElementById('smForm');
fm.action = "whatever";
 

Re: change from action URL on-the-fly

Posted: Tue Jan 20, 2009 10:54 am
by potato_chip
Burrito wrote:

Code: Select all

 
fm = document.getElementById('smForm');
fm.action = "whatever";
 
could you please be more specific? Thank you very much!

Re: change from action URL on-the-fly

Posted: Tue Jan 20, 2009 11:08 am
by Burrito

Code: Select all

 
<script>
function changeAction(where)
{
  fm = document.getElementById("smForm");
  fm.action = where;
  fm.submit();
}
</script>
 
<select name="whatever" onChange="changeAction(this.value)">
<option value="http://www.google.com">google</option>
<option value="http://www.yahoo.com">yahoo</option>
<option value="http://www.msn.com">msn</option>
</select>
 

Re: change from action URL on-the-fly

Posted: Tue Jan 20, 2009 12:22 pm
by potato_chip
Acutually I'm using hyperlink to submit a form, not a submit button or dropdown list.

Re: change from action URL on-the-fly

Posted: Tue Jan 20, 2009 12:23 pm
by Burrito
then call the function from the link

Code: Select all

 
<a href="javascript&#058;void(0)" onClick="changeAction()">click me</a>