View Full Version : Help with self filling form

07-31-2011, 02:10 AM
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

Old Pedant
07-31-2011, 06:10 AM
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?

08-04-2011, 06:16 AM
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?

Philip M
08-04-2011, 09:10 AM
Is this what you are looking for?

<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>
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];

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.

08-04-2011, 09:14 AM
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.

08-09-2011, 05:40 AM
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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum