0

I am trying to convert the SELECT OPTION Value users selects to Decimal and I'm getting this error message: The input value () cannot be formatted as a number. The first parameter value for a FormatNumber call must be a numeric type supported by the requested format. Value: Format: 0.00

I would appreciate if anyone can point the right direction/function to use that.

<html>
<head>

</head>

<body>

<form action="#">
      <label style="color:red; font-weight:bold;background-color:#ffff66;"> Choose Options to display: </label> &nbsp;&nbsp;&nbsp;  
      <select  Name="chosenOption">
      <option value="1">  Display All &nbsp;&nbsp;&nbsp; </option>  
      <option value="100"> 100% Blocked </option>   
      <option value="70">   70% Blocked </option>   
      <option value="50">   50% Blocked </option>   
      <option value="20">   20% Blocked </option>  
      <option value="10">   10% Blocked </option> 
      <input type="Submit"  value="Click to Filter "/>
    </form>

%%[

  VAR @chosenOption_v, @chosenOption_vv
  SET @chosenOption_vv = RequestParameter('chosenOption');
  SET @chosenOption_v = FormatNumber(@chosenOption_vv,"F2",'en-US');   /* Fails to convert to Decimal/Fixed */ 

]%%

<table>
    <tr>
        <td>%%=v(@chosenOption_vv)=%%</td>
    </tr>
</table>

</head>
</body> 
</html>

1 Answer 1

1

Ampscript is server-side, while the form to submit the option value is client-side. Therefore, the AMPscript code was already executed when it hadn't received any input value yet.

The way to solve this is that you can use an additional handler page, so the handler page will progress the data when the submitted form sends the form data to it.

Form page:

<html>
<body>
<form action="%%=CloudPagesURL(123)=%%" method="post">
      <label style="color:red; font-weight:bold;background-color:#ffff66;"> Choose Options to display: </label> &nbsp;&nbsp;&nbsp;  
      <select  Name="chosenOption">
      <option value="1">  Display All &nbsp;&nbsp;&nbsp; </option>  
      <option value="100"> 100% Blocked </option>   
      <option value="70">   70% Blocked </option>   
      <option value="50">   50% Blocked </option>   
      <option value="20">   20% Blocked </option>  
      <option value="10">   10% Blocked </option> 
      <input type="Submit"  value="Click to Filter "/>
    </form>
</body> 
</html>

In this example, 123 is the handler cloudpage ID.

Handler page:

%%[

  VAR @chosenOption_v, @chosenOption_vv
  SET @chosenOption_vv = RequestParameter('chosenOption');
  SET @chosenOption_v = FormatNumber(@chosenOption_vv,"F2",'en-US');
]%%
%%=v(@chosenOption_vv)=%%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .