SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    130
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Arrow How Do I Populate a Hidden Input Field?

    Hi, here's the code that I've written that doesn't work, please have a look at it because it'll help you understand what I want to do...

    HTML Code:
    <script language="JavaScript" type="text/javascript">
    //function that should populate the hidden field
    function popGender(val) {
      switch (val) {
        case '16130':
        case '16132':
        case '16133':
          gender = 3143; //female
          break;
        case '16131':
          gender = 3142; //male
          break;
      }
      document.ghm_form.q434.value = gender;
    }
    </script>
    
    <!-- Title - this field is supposed to use it's data to populate the gender field below -->
    <select name="q1004" onchange="popGender(this.value)">
    <option value="">--Select One--
    <option value="16130">Miss
    <option value="16131">Mr.
    <option value="16132">Mrs.
    <option value="16133">Ms.
    </select>
    
    <!-- Gender (should be populated when title is selected) -->
    <input type="hidden" name="q434" value="">
    Does somebody know an alternative way to do this that does work, and that works across all browsers?

  2. #2
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you give it an id, then you could use

    Code JavaScript:
    document.getElementById(id).value = gender;
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should also make sure gender is a string value, not a number, since input field values are strings.

    Code JavaScript:
    function popGender(val) {
      switch (val) {
        case '16130':
        case '16132':
        case '16133':
          gender = "3143"; //female
          break;
        case '16131':
          gender = "3142"; //male
          break;
      }
      document.getElementById("q434").value = gender;
    }
    Code HTML4Strict:
    <input type="hidden" name="q434" id="q434" value="">
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    130
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll have a look at that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •