Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating random numbers within form

Status
Not open for further replies.

planeboy747

Technical User
Joined
Jan 11, 2005
Messages
41
Location
US
I have a form that I'm working on, which you can view at:



I have only a part of this form functional with the JavaScript I already have. At the top of the form there is a place to enter the number of customers. Once you select that number, it autopopulates the "Customer Names" section (id="nameSet) with the appropriate number of fields.

The next section is Terms of Contract, which has an image button labeled id="agreeButton". I would like once someone clicks this button for it to show the Authorization Code and the Order Numbers tables below, as you currently see on the form. I don't want those to sections to initially show up when the form loads. I would like those to only load when the agree button is clicked.

In the Authorization Code section, I have a hidden field labeled id="code". I would like for JavaScript to fill that hidden field with a random four digit alpha numeric number that starts with the number 4 (the other 3 characters are random alpha/numeric). The characters i,o,1,0 need to be excluded from the random selection process. In addition, you'll see where I've listed just a sample Authorization Code in bold of 4ZXY (just for display purposes), just to show how it should be presented in the text. I'm thinking if a document.write could read the id="code" and then populate this section of the form with that code.

For the Order Numbers Section, I would like these fields to automatically populate based on the number entered into the id="nameSet" (Number of customers field). This section, like the Authorization Code section, needs to show up with the Authorization Code section, only when the Agree button has been clicked. All the order numbers start with 332, so that's why I have the number 332 before the form field, and it needs to stay that way, because since that's a constant, I never need to see those numbers entered into the field.

Okay, so the bottom line question is how to I get the code to this? LOL. I'm still new to JS, so speak slow.(smile) And if you can show me, that would be wonderful!

Well I can't wait to hear you guys feedback on this one! Thanks for your help, you guys are always so awesome!

J
 
1. Multiple customers does not work in firefox!

2. How about something like this for the random number generator?
Code:
var valid = new Array("2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
function getRandom()
{
  var num = Math.floor(Math.random() * valid.length);
  return valid[num];
}

function randomString()
{
  return "4" + getRandom() + getRandom() + getRandom();
}

3. The showing of the last two seems pretty easy, just call the function authorize() once the agree button is pressed.
Code:
function authorize()
{
  var elem = document.getElementById("second"); // the stuff
  // you want to hide is put in a div called second
  // with display=none
  elem.style.display = "block";
}

Any more questions?

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
wow chessbot, thanks for the code, you're awesome...I've still got a couple questions.

To answer your first item, unfortunately, Firefox is not supported on this site yet (sad I know).

I understand the code for the random number generator. Now once the agree button is pressed, I'm still confused how that number will get into the "code" field and then have document write populate in the Authorization Code table?

I'm guessing on the div tags you'r saying put the Authorization Code and and Order Numbers tables behind the tags, and then when the agree button is pressed those will show? Even if they show, how will I get the Order number fields to autopopulate based on the number selected in "nameSet" field (Number of customers).

Thanks
J
 
also, forgot to mention, once the Agree button (image) has been clicked, how do I make it disappear?

thanks
j
 
I tried your code, do I need to ad an onClick="authorize()" to the button to make this work?


thanks
j
 
hey, i put onClick="authorize(second)" and it worked! thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top