How to use a <input type="hidden"> with Javascript

Discussion in 'Programming' started by wicketywick, Oct 29, 2009.

  1. #1
    I want to complete my form with a bit of Javascript (which I know next to nothing about, to fill out a hidden input field).

    The input field is:

    <input type="hidden" name='field[537,0]' value='' />

    the dropdown selection positions are:

    <select name='field[539,0] >
    <option value='Herr'>Herr</option>
    <option value='Frau'>Frau</option>

    the command I am looking for would be:

    if "Herr" is selected, add "sehr geehrter" to
    "field[537,0]" and if "Frau" is selected add "sehr geehrte".

    How does that get done? I am also willing to compensate for the help - I thought of going to a freelance website, but I think this is just a small project - I was also hoping to complete the form today or tomorrow.
     
    wicketywick, Oct 29, 2009 IP
  2. FCM

    FCM Well-Known Member

    Messages:
    669
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    155
    #2
    Well I will give you part of the answer.

    You are going to have to have some sort of event handler whether its onFocus onBlur or onClick.
    Which triggers the value in the hidden field. Although this isn't what you are looking for below it should give you a basic idea as to how it works.

    
    <form name=testform>
    <input name="textn" value="some value" type="text">
    <input name="hiddenvalue" type="hidden">
    </form>
    
    <script language="javascript">
    var cbobject= document.testform.textn;
    document.testform.hiddenvalue = 'some value';
    </script>
    
    Code (markup):
    The script code will make it where the documents hidden field has a value.

    http://www.hscripts.com/tutorials/javascript/dom/textfield-events.php
     
    FCM, Oct 29, 2009 IP
  3. wicketywick

    wicketywick Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for that.
    so I added the script ( I changed the names of course):

    <script language="javascript">
    var cbobject= document.subscribeform.field[539,0];
    document.subscribeform.field[537,0] = 'some value';
    </script>

    <select name='field[539,0]' >
    <option value='Herr'>Herr</option>
    <option value='Frau'>Frau</option>

    I don't know what to put in place of 'some value', what I would like is:

    if "Herr" is selected, add "er" to
    "field[537,0]" and if "Frau" is selected add "e" to the field.

    I looked at the tutorials, but I didn't get much further.
     
    wicketywick, Oct 29, 2009 IP