Hello, Will appreciate a quick help hear if you can. I have 3 inbut box values (strings) from a form - 1. form.box1.value 2. form.box2.value 3. form.box3.value I want to declare a variable (var) that'll combine all the above 3 values into one string. var = finalstring tell me the code; Help is appreciated.. thanks
var finalstring = form.box1.value + ' ' + form.box2.value + ' ' + form.box3.value; You'll probably want to wait and do this AFTER the user has filled out the form box by calling it when onsubmit happens with the form.
In each input box's onBlur() function, check to see that each box is not empty. When each one has something, set your variable. Or, in your form validation, tell the user to fill in any empty box. If validation gets past that point (no empty boxes), set the variable, then do whatever else you need to do to validate the form.
This would check the lengths of the text entered into your text boxes before the form submits. If a box is empty, the user gets an alert and the form won't submit. (You can test boxes for valid data here too - phone numbers - minus dashes, spaces and parentheses - should contain only 0-9, you can use a regex to test email addresses, etc.) <javascript> function checkLengths() { var l = document.getElementById("nameId").value; if(l.replace(/^\s+|\s+$/g,"").length == 0) { alert('You have to enter a name.'); return false; } else { l = document.getElementById("addressId").value; if(l.replace(/^\s+|\s+$/g,"").length == 0) { alert('You have to enter an address.'); return false; } //more tests return true; } </javascript> <form action="submit.htm" onSubmit="checkLengths()"> Name: <input type="text" id="nameId" /> //etc. Code (markup): (No guarantee that the code is bug-free - I just whipped it out fast.)