+ Reply to Thread
Results 1 to 3 of 3

Thread: Disabled HTML Form and Javascript

  1. #1
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Disabled HTML Form and Javascript

    i have an html form. in it, there is a list of radio buttons, the last of which is 'other'. i have a text input that is to be disabled unless the 'other' radio button is selected. however, i can't seem to get the javascript to work.

    here's the form:
    HTML Code:
    <form name="contact" action="process.php" method="post">
    
    <label class="text">Name:<input class="name" name="name" type="text" value="" /></label><br />
    
    <label class="text">Email:<input class="email" name="email" type="text" value="" /></label><br />
    
    <label class="text">Subject:<input class="sub" name="sub" type="text" value="" /></label><br />
    
    <label class="text">Purpose:</label><br />
    
    <label class="button"><input class="purpose" id="1" name="purpose" type="radio" value="Job Offer" onchange="radio_checker();" />Job Offer</label><br />
    
    <label><input class="purpose" id="2" name="purpose" type="radio" value="Question/Comment" onchange="radio_checker();" />Question/Comment</label><br />
    
    <label><input class="purpose" id="3" name="purpose" type="radio" value="Other" onchange="radio_checker();" />Other</label>
    
    <input class="purposeOther" id="4" name="other" type="text" value="" disabled="true" /><br />
    
    <label class="msg">Message:<textarea class="msg" name="msg" value=""></textarea></label>
    
    <a href="javascript:submit();" class="submit">Send</a>
    <a href="javascript:reset();" class="reset">Reset</a>
    
    </form>
    and the javascript:
    Code:
    function radio_checker() {
    	if (document.contact.3.checked) {
    		document.contact.purposeOther.disabled = false;
    		document.contact.purposeOther.focus();
    	}
    	else {
    		document.contact.purposeOther.disabled = true;
    	}
    }
    please help.
    Last edited by kbjradmin; 02-04-2009 at 04:04 PM.

  2. #2
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    Re: Disabled HTML Form and Javascript

    this should work
    document.contact.[name].attribute
    [name] can only be the value of the attribute name, not id or class. if you want to use id or class use a getElementbyID function or getElementsByClassName
    Code:
    function radio_checker() {
    	if (document.getElementById("3").checked == true) {
    		document.contact.other.disabled = false;
    		document.contact.other.focus();
    	}else {
    		document.contact.other.disabled = true;
    	}
    }
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  3. #3
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: Disabled HTML Form and Javascript

    thank you very much nightscream.

+ Reply to Thread

Similar Threads

  1. A HTML + CSS Basic Tutorial
    By Zenax in forum Tutorials
    Replies: 14
    Last Post: 09-02-2011, 01:42 PM
  2. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  3. Javascript submit to form submit
    By e85andyou in forum Programming Help
    Replies: 2
    Last Post: 11-03-2008, 08:33 AM
  4. Javascript form to PHP
    By driveflexfuel in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-28-2008, 11:15 PM
  5. Javascript form to PHP
    By driveflexfuel in forum Programming Help
    Replies: 2
    Last Post: 10-16-2008, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers