SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    London, ON
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing type property on text box.

    A quick question:

    How do you change type property on text box from 'hidden' to 'text' in java script.

    Ex:

    function doStuff()
    {
    // this line gives me a run time error saying
    // Could not get the type property. This command is not supporteed.
    document.myForm.myTextBox.type = "text";
    }

    So how you do it LOL?

    Thanks

    Luke

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    This worked for me:

    JS
    Code:
    <script type="text/javascript">
    function changeFieldType(fieldName) {
      if (document.getElementById) {
         if (document.getElementById(fieldName).getAttribute("type") == "hidden") {
             document.getElementById(fieldName).setAttribute("type", "text");
         }
         else {
             document.getElementById(fieldName).setAttribute("type", "hidden");
         }
      }
    }
    </script>
    HTML
    HTML Code:
    <form>
    <input type="hidden" name="hidden" id="hidden" />
    <input type="button" name="hello" value="Change! :)"
     onclick="changeFieldType('hidden');" />
    </form>
    Change the argument to match the ID of the form field you're trying to change.

  3. #3
    SitePoint Member
    Join Date
    Jul 2003
    Location
    London, ON
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx very much for the reply but i found even simpler solution LOL ...

    Here it is:

    JS:

    function setStyle()
    {

    if( 'some condition' )
    { document.frmSurvey.txtCourseOther.style.visibility = "visible";
    }
    else
    {
    document.frmSurvey.txtCourseOther.style.visibility = "hidden";
    }

    }

    HTML:

    <input name="txtCourseOther" size="39" style="VISIBILITY: hidden">


    Thanks for the response, I appreciate it.

    Luke


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
  •