Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to make sure a user selected something in a form?

    Hey guys I am working on a project and our teacher is making us make sure that at least one of the group of text boxes, check boxes, and selection lists are checked. How would I do this? Any help would be greatly appreciated!

    :code:

    <strong>Select your current class rank:</strong><br /> <!--Displays the class rank radio buttons//-->
    <input type="radio" name="registrationrank" value="Freshman" />Freshman
    <input type="radio" name="registrationrank" value="Sophomore" />Sophomore
    <input type="radio" name="registrationrank" value="Junior" />Junior
    <input type="radio" name="registrationrank" value="Senior" />Senior

    <p>Select your major(s).</p> <!--Displays the major check boxes//-->
    <p>
    <input type="checkbox" name="majors" value="business" />Business<br />
    <input type="checkbox" name="majors" value="cet" />Computer Engineering Technology<br />
    <input type="checkbox" name="majors" value="cis" />Computer Information Systems<br />
    <input type="checkbox" name="majors" value="cs" />Computer Science<br />
    <input type="checkbox" name="majors" value="other" />Other<br />
    </p>

    <h3>Select the semester for which you are registering.</h3>
    <p><select name="semester">
    <option value="">Choose One:</option>
    <option value="fall">Fall</option>
    <option value="spring">Spring</option>
    <option value="summer">Summer</option>
    <option value="special_session">Special Session</option>
    </select></p>

    <h3>Select the courses for which you are registering.</h3> <!--Displays the courses drop down list and all can be selected//-->
    <p><select multiple="multiple">
    <option value="cis110">CIS 110 Intro to Information Systems</option>
    <option value="cis120">CIS 120 Application Programming I</option>
    <option value="cis220">CIS 220 Application Programming II</option>
    <option value="cis299">CIS 299 Systems Analysis I</option>
    <option value="cis322">CIS 322 Database Application Development</option>
    <option value="cis332">CIS 332 Web Programming II</option>
    <option value="cis341">CIS 341 CISCO CCNA 1</option>
    <option value="cis343">CIS 343 CISCO CCNA 3</option>
    <option value="cis352">CIS 352 Global, Economic and Social Ethical Issues in Computing</option>
    <option value="cis492">CIS 492 Senior Project II</option>
    </select></p>

    :code:

    Those are all of my items that are included. Thank you for your time!
    Last edited by codenewb; 11-27-2012 at 12:21 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Look here:

    http://www.codingforums.com/rules.htm

    Look at Rule 1.5.

    So...

    You make an effort and if you run into a bug we will likely help you. But don't expect us to do your homework for you.

    One hint: Google (or even search this forum) for "form validation".
    Last edited by Old Pedant; 11-26-2012 at 11:09 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sorry this isn't my whole hw but a tiny part of a large assignment but I apologize I wasn't expecting anyone to do it for me just suggestions. But I might have found something but I cant get it to work right. I have made a function that is supposed to check to see if the class ranking is selected.

    :code:

    function classRankCheck() {
    for (var i=0;i<document.forms[0].registrationrank.length;i++)
    {
    if(document.forms[0].registrationrank[i].checked)
    var rankselect=true;
    }

    if(!productselect)
    {
    window.alert("Please select a class rank!");
    return false;
    }
    }

    :code:

    Am I close to this at all? haha....

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Two bugs:

    (1) You didn't initialize the variable rankselect so if nothing is selected it won't have any value at all. So initialize the variable to false *before* the loop and don't use var inside the loop.

    (2) Ummm...where did productselect come from?

    (3) [Extra credit, though your instructor may not like it] How can you code that without needing the rankselect variable, at all?

    &&&&&&&&&&

    I have to ask: Why is "majors" a set of checkboxes? Are you expecting people to check more than one major???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    codenewb (11-27-2012)

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    actually yes! lol our teacher made sure to tell us that they could select more than one major at a time.....(idk why)

    and product select was a mistake haha that was supposed to be rank select

    thanks for all of your assistance though...I am not very good at any coding yet =[ but I am getting there!


  •  

    Posting Permissions

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