SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hide/Show text field on radio select - prob

    Hi All,

    I'm a *real* JS noob and need to show or hide a text field when a radio is selected. This is what I've tried so far.

    HTML Code:
    function toggleT(_w,_h) {
    if (document.all) { // is IE
    if (_h=='s') eval("document.all."+_w+".style.display='block';");
    if (_h=='h') eval("document.all."+_w+".style.display='none';");
    } else { // is NS? 
    if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
    if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
    }
    }
    And this is a segment from the form:

    HTML Code:
    <input type="radio" name="contact" value="email" onClick="toggleT('field1','s')" />
    	 Please contact me by email</label>
    	 <br />
    	 <span id="field1">
    	 <input name="email" type="text" id="email" size="20" maxlength="35"/>
    	 <br />
    	 <br /></span>
    I found this function and changed the way the div (that contains my text field) is hidden/shown by replacing 'visibility=visible' to the above to the form would collapse and expand. Now, that works ok, but the main problem is that it won't work on FF. Can anyone enlighten me as to why this is? And are there any better methods to do this?

  2. #2
    SitePoint Enthusiast Mark_Elford's Avatar
    Join Date
    Oct 2003
    Location
    England, Wiltshire
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, trying to do something thery similar myself..

    I have repeating elements on my page dragged from a db. I have created a function to alter my form elements on the click of a checkbox.

    Each checkbox, cbobox have the same suffix (id)

    function checkit(ref)

    {

    //alert(ref)

    if (eval("frmPrintLabel.chk_" + ref + ".checked") == true)

    {

    <B>Object.eval("frmPrintLabel.Reason_" + ref + ".Disabled" = "false");</B>

    alert("enabled")

    }

    else

    {

    alert("disabled")

    //eval("frmPrintLabel.Reason_" + ref + ".Disabled" = True);

    }



    }

    The if eval works, but I am unable to get the eval to enable my form elements when the check is clicked. The alerts (work) so I am guessing its something to do with the way I am constructing my eval..

    Like the previous post am I doing this correctly.?

    Is there a better way..


    Thanks

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do this:
    Code:
    function toggleT(_w,_h) {
        if (_h=='s') document.getElementById(_w).style['display']='';
        else document.getElementById(_w).style['display']='none';
    }

  4. #4
    SitePoint Enthusiast Mark_Elford's Avatar
    Join Date
    Oct 2003
    Location
    England, Wiltshire
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect. Thanks for the answer peterbe..


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
  •