Web Analytics Made Easy -
StatCounter prefix form values - CodingForum

Announcement

Collapse
No announcement yet.

prefix form values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • prefix form values

    hi.

    I have this nifty little script I am using to generate a unique reference number for everyone that fills in my form. I have the same form in 2 locations, and it is important that I can tell (from the reference number alone) which location it came from.

    I know all about sending the url etc from a form in its own hidden field, but for 100 very boring reasons I need to be able to tell from the number. I have been trying to prefix the number with letters, so from one location the number would be AAxxxxxxxx, and from the other location it would be BBxxxxxx but I have been unable to do so.

    Any suggestions? Form script below (has had all irrelevant fields taken out to simplify)

    Code:
    <form id="formname" name="formname" method="post" action="./testcontrol.php">
    <input type="text" name="orderNum" id="orderNum" />
    <SCRIPT type="text/javascript">
    var d = new Date();
    var yr =( d.getYear() ).toString();
    yr = yr.charAt(3); // final digit
    var mo = ( d.getMonth() ). toString();
    if ( mo.length <2 ) {mo = 0 + mo}
    var hrs = ( d.getHours() ). toString();
    if (hrs.length <2) {hrs = 0 + hrs}
    var mns = ( d.getMinutes() ).toString();
    if (mns.length <2) {mns = 0 + mns}
    var secs = (d.getSeconds() ).toString();
    if (secs.length <2) {secs = 0 + secs}
    var oNum = yr + mo + hrs + mns + secs;
    document.formname.orderNum.value = oNum;
    </SCRIPT>
    </form>

  • #2
    How about removing the name attribute from the form (as that’s outdated, deprecated, and invalid), wrapping all form controls in a block-level element (since that’s the only valid way), and doing something like this:
    Code:
    <form id="form1" method="post" action="./testcontrol.php">
    	<div>
    		<input type="text" name="orderNum" id="orderNum" />
    	</div>
    	<script type="text/javascript">
    	var d = new Date();
    	var yr =( d.getYear() ).toString();
    	yr = yr.charAt(3); // final digit
    	var mo = ( d.getMonth() ). toString();
    	if ( mo.length <2 ) {mo = 0 + mo}
    	var hrs = ( d.getHours() ). toString();
    	if (hrs.length <2) {hrs = 0 + hrs}
    	var mns = ( d.getMinutes() ).toString();
    	if (mns.length <2) {mns = 0 + mns}
    	var secs = (d.getSeconds() ).toString();
    	if (secs.length <2) {secs = 0 + secs}
    	var oNum = yr + mo + hrs + mns + secs;
    
    	[COLOR="Red"]var formID = document.forms['form1'].getAttribute('id');
    	document.forms['form1'].orderNum.value = formID + oNum;[/COLOR]
    	</script>
    </form>
    (I haven’t tested it.)

    Edit: Oh and by the way: Maybe this can be of help: http://javascript-coder.com/javascri...rm-objects.htm
    Last edited by VIPStephan; Apr 2, 2009, 01:51 PM.
    Stop solving problems you don’t yet have!

    Comment

    Working...
    X