Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Hidden field script needed i think

Options
  • 18-12-2008 5:39pm
    #1
    Registered Users Posts: 44


    Hi
    I have the following set of radio buttons, each with a different value. Basically depending on which is selected i need the hiddenfield to hold whether it is Euro/Sterling or Dollar. Would anyone be able to help me out here.



    Euro<input name="Currency" type="radio" value="1" checked id="currency">
    Sterling <input name="Currency" type="radio" id="currency" value="<%=(rsSterlingVal.Fields.Item("CurrencyVal").Value)%>">
    Dollar<input name="Currency" type="radio" id="currency" value="<%=(rsDollarVal.Fields.Item("CurrencyVal").Value)%>">

    <input type="hidden" name="hiddenField" id="hiddenField">


Comments

  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Why don't you just read the contents of the form, as normal, and then put the value of the radio button (or a corresponding value) in a variable? You can then reference that variable in the hidden field.

    For example -
    <?php
    // myForm.php
    
    if ($_GET['hiddenfield'])
     $hiddenField = $_GET['hiddenfield'];
    else
     $hiddenField = "";
    
    echo '
    <html>
    <body>
    <form method="get" action="myForm.php">
    <!-- put your radio buttons here -->
    <input type="hidden" name="hiddenField" value="<?=$hiddenField;?>">
    <input type="submit" value="Submit">
    </body>
    </html>';
    
    ?>
    


  • Registered Users Posts: 44 MikeFantana


    Basically,


    This is an insert statement into a table which will hopefully catch the 'the currency and the currencyrate e.g. ''Dollar' for Currency and '0.78' for the currency Rate. I would like to achieve this by one selection as opposed to 2 selections.


  • Registered Users Posts: 44 MikeFantana


    AARRRGH wrote: »
    Why don't you just read the contents of the form, as normal, and then put the value of the radio button (or a corresponding value) in a variable? You can then reference that variable in the hidden field.

    For example -
    <?php
    // myForm.php
     
    if ($_GET['hiddenfield'])
     $hiddenField = $_GET['hiddenfield'];
    else
     $hiddenField = "";
     
    echo '
    <html>
    <body>
    <form method="get" action="myForm.php">
    <!-- put your radio buttons here -->
    <input type="hidden" name="hiddenField" value="<?=$hiddenField;?>">
    <input type="submit" value="Submit">
    </body>
    </html>';
     
    ?>
    

    Sorry i should have mentioned im using asp not php...my bad


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    I guessed from your code you were using ASP, but PHP syntax is fairly similar so it should be readable.

    This is an insert statement into a table which will hopefully catch the 'the currency and the currencyrate e.g. ''Dollar' for Currency and '0.78' for the currency Rate. I would like to achieve this by one selection as opposed to 2 selections.

    The user should only choose his currency. It is up to you to define the currency rate.


  • Registered Users Posts: 44 MikeFantana


    AARRRGH wrote: »
    I guessed from your code you were using ASP, but PHP syntax is fairly similar so it should be readable.

    The user should only choose his currency. It is up to you to define the currency rate.

    Currently the currency rate is pulled in using a seperate table via a recordset e.g. <%=(rsSterlingVal.Fields.Item("CurrencyVal").Value)%> which inturn is inserted in the table no problem, its just i need to be able to trap the currency type when inserting.


  • Advertisement
  • Registered Users Posts: 177 ✭✭mercuroman


    you could use Javascript. something like this:

    <script type="text/javascript">
    function toggleCurrency(radioButton)
    {
    hiddenField.text = radioButton.value;
    }
    </script>

    Euro<input name="Currency" type="radio" value="1" checked id="currency" value="Euro" onclick="toggleCurrency(this)">
    Sterling <input name="Currency" type="radio" id="currency" value="<%=(rsSterlingVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">
    Dollar<input name="Currency" type="radio" id="currency" value="<%=(rsDollarVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">

    <input type="hidden" name="hiddenField" id="hiddenField">


  • Registered Users Posts: 44 MikeFantana


    mercuroman wrote: »
    you could use Javascript. something like this:

    <script type="text/javascript">
    function toggleCurrency(radioButton)
    {
    hiddenField.text = radioButton.value;
    }
    </script>

    Euro<input name="Currency" type="radio" value="1" checked id="currency" value="Euro" onclick="toggleCurrency(this)">
    Sterling <input name="Currency" type="radio" id="currency" value="<%=(rsSterlingVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">
    Dollar<input name="Currency" type="radio" id="currency" value="<%=(rsDollarVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">

    <input type="hidden" name="hiddenField" id="hiddenField">


    Thanks for that code, but its not catching what each buttons currency is. Below is my whole page (minus the insert statement)



    <[EMAIL="%@LANGUAGE=&quot;VBSCRIPT"]%@LANGUAGE=&quot;VBSCRIPT[/EMAIL]" CODEPAGE="65001"%>
    <!--#include file="../Connections/sqs.asp" -->
    <%
    Dim rsDollarVal
    Dim rsDollarVal_numRows
    Set rsDollarVal = Server.CreateObject("ADODB.Recordset")
    rsDollarVal.ActiveConnection = MM_sqs_STRING
    rsDollarVal.Source = "SELECT * FROM dbo.tblCurrencyIE where Currency = 'Dollar'"
    rsDollarVal.CursorType = 0
    rsDollarVal.CursorLocation = 2
    rsDollarVal.LockType = 1
    rsDollarVal.Open()
    rsDollarVal_numRows = 0
    %>
    <%
    Dim rsSterlingVal
    Dim rsSterlingVal_numRows
    Set rsSterlingVal = Server.CreateObject("ADODB.Recordset")
    rsSterlingVal.ActiveConnection = MM_sqs_STRING
    rsSterlingVal.Source = "SELECT * FROM dbo.tblCurrencyIE Where currency ='Sterling'"
    rsSterlingVal.CursorType = 0
    rsSterlingVal.CursorLocation = 2
    rsSterlingVal.LockType = 1
    rsSterlingVal.Open()
    rsSterlingVal_numRows = 0
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function toggleCurrency(radioButton)
    {
    hiddenField.text = radioButton.value;
    }
    </script>
    </head>
    <body>
    <form name="form1">
    <p>
    Euro
    <input name="Currency" type="radio" value="1" checked id="currency" onclick="toggleCurrency(this)">
    </p>
    <p>Sterling
    <input name="Currency" type="radio" id="currency" value="<%=(rsSterlingVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">
    </p>
    <p>Dollar
    <input name="Currency" type="radio" id="currency" value="<%=(rsDollarVal.Fields.Item("CurrencyVal").Value)%>" onclick="toggleCurrency(this)">
    </p>
    <p>
    <input type="hidden" name="hiddenField" id="hiddenField">
    <br />
    <input type="reset" name="Reset" id="button" value="Reset" />
    <label>
    <input type="submit" name="button2" id="button2" value="Submit" />
    </label>
    <br />
    </p>
    </form>
    </body>
    </html>
    <%
    rsSterlingVal.Close()
    Set rsSterlingVal = Nothing
    %>
    <%
    rsDollarVal.Close()
    Set rsDollarVal = Nothing
    %>


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    If the rate is already in the database, then just do another SQL statement upon the form submission to get it.

    It would be very easy for anyone with a bit of JavaScript knowledge to change the contents of a hidden form field.


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    eoin wrote: »
    If the rate is already in the database, then just do another SQL statement upon the form submission to get it.

    It would be very easy for anyone with a bit of JavaScript knowledge to change the contents of a hidden form field.

    Yeah, I'm having a hard time understanding the OPs reasoning.

    OP: Is this a commerical application you are developing (i.e. you don't have to use hidden form values), or is it some sort of assignment where you must use hidden form values?


Advertisement