SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    PA
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically create hidden fields

    I create hidden fields in JS to hold values for use on submit. The way I create them is something like this…

    Code:
    var hdnTotField=opener.document.getElementById("hdn_" + valType + "_tot");
    var tot = hdnTotField.value;
    x.innerHTML+="<input type='Hidden' id='hdn_" + valType + "_" + tot + "' name='hdn_" + valType + "_" + tot + "' value='"+optionalVal+"'><span onmouseover=hlFlip(this,'delValue') onmouseout=hlFlip(this,'undelValue') class='undelValue' onclick=delme('"+val+"','"+valType+"',this,"+tot+")>"+val+"</span>&nbsp;";
    hdnTotField.value = parseInt(tot,10)+1;


    Is there a better way to do this like maybe…

    Code:
    var hidden = new hidden
    hidden.value=”blah”
    hidden.name=”hdnName”
    hidden.id=”hdnID”
    


    This would make much cleaner code.

    Thanks for your thoughts.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    PA
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that "Premature submit"
    Something like this would be much cleaner code...

    Code:
     var hidden = new hidden hidden.value=”blah” hidden.name=”hdnName” hidden.id=”hdnID”
    Thanks

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var hidden = document.createElement('input');
    hidden.setAttribute('type', 'hidden');
    hidden.setAttribute('value', 'blah');
    hidden.setAttribute('name', 'hdnName');
    hidden.setAttribute('id', 'hdnID');
    document.getElementById('formId').appendChild(hidden);
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    PA
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome! This is exactly what I was look for. Thanks

  5. #5
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must spread some Reputation around before giving it to Jeff Lange again.
    Of course, that's just my opinion. I could be wrong.


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
  •