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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with self filling form

    Hello, I'm a javascript beginner and need some help with a form that has 1 dropdown and two text boxes. when an item is selected in the dropdown it will autofill a number into the first text box that will be the highest number allowed. i.e. it may put a 30 so the range would be 1-30. and when a number is filled there it will do a simillar function for the second text box. also I need the script to make sure the number input is within the range when it leaves focus so it doesn't cause problems if the user types in a number larger than the range allows. I can't even seem to get the auto fill part to work so any help on it and/or the check part of the script would be awesome

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    It would help if you would tell us WHAT number has to be put into the first text field when WHICH <option> in the <select> is chosen.

    That is, what is the relationship between the <option> and the "highest number allowed"??

    But then I really don't understand "when a number is filled there it will do a simillar function for the second text box". Ummm...so if <option> number 7 is selected, then we choose 28 as the "highest number allowed". And when we put the 28 into text box 1 then we have another function that fills in text box 2...but with what?

    And if all of the numbers in the text box are filled in by the script, then why do you need to worry about the user typing in anything?? Where would the user type in something? If not into text box 1 or text box 2, then where?

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry if this seems confusing. What I am doing is having each <option> in the <select> be a different subject, and the first textbox will be a page, and the second textbox will be a line. So when you select the subject the first textbox will be automatically filled with the number of pages associated with that particular subject, and the second textbox will autofill with the number of lines associated with the page in the first textbox. does that make more sense?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,309
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Is this what you are looking for?

    Code:
    <select id = "subject" onchange = "show()">
    <option value = "0~0">Select a subject .....</option>
    <option value = "4~112">Subject 1</option>
    <option value = "6~147">Subject 2</option>
    <option value = "2~34">Subject 3</option>
    <option value = "5~128">Subject 4</option>
    </select>
    Number of pages for this subject <input type = "text" id = "numPages" size = "2" readonly>
    Number of lines for this subject <input type = "text" id = "numLines" size = "3" readonly>
    
    
    <script type = "text/javascript">
    function show() {
    document.getElementById("numPages").value = "";
    document.getElementById("numLines").value = "";
    var num = document.getElementById("subject").value;
    var numSplit=[];
    numSplit = num.split("~");
    if (numSplit[0] >0) {
    document.getElementById("numPages").value = numSplit[0];
    document.getElementById("numLines").value = numSplit[1];
    }
    }
    </script>

    I am not clear whether the first textbox should show a specific page number, or the number of pages in a certain book which are devoted to that subject.
    Last edited by Philip M; 08-04-2011 at 09:13 AM. Reason: Typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    To me, sounds like this could be homework.

    Post the code you have so far and we can try to help you get it working.

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well I really don't know much about JavaScript and I have no code so far because everything I have tried hasn't work and I deleted it. No it's not for homework, I am making a website and I am trying to get the form to have limitations. the site is http://solascriptura.mywebcommunity.org and currently you can put anything you want in the textboxes on the bible search and I am trying to set limits. I was just going to have it autofill the number of chapters in the selected book and the number of verses in the selected chapter because I haven't though of a better way of doing it. I am also wanting to make the script check when a number is typed in to make sure it is within the range of chapters/verses


  •  

    Posting Permissions

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