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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Unhappy Concatinating values into a textbox

    I have a problem with this code.

    I am trying to perform validation on the three drop down menus which give the DATE, MONTH and the YEAR.

    I am putting the values of each into a hidden text box then
    performing validation on the text box.

    However, i need to allow the user to change the drop down value (by pulling it down and
    selecting a value) and change the textbox automatically.

    It works if i select 1 date, 1 month then 1 year. But, if i change the year, month or date again it just adds
    to the textbox.

    for example,

    works: 6/6/2005

    then if i change the year again (without a refresh of the page) the box reads:

    6/6/20052004

    How can i stop this?

    Help appreciated.

    Code:
    // Check the INFANT Birthday
    // 2 Year Old Check
    
    function checkBirthday(obj)
     {
    	if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(obj.value) ) {
    		alert( "Invalid date supplied - must be format DD/MM/YYYY" );
    		//obj.focus();
    		return;
    	}
    	
    	var d = new Date();
    	var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
    	
    	var diff = d.getDiff(d2, "y")
    	if( isNaN(diff) ) {
    		alert( "Invalid date supplied" );
    	}
    	else if( diff < 2 ) {
    		alert( "This IS an INFANT \n they are younger that 2" );
    		infant = true;
    		document.form.submit();
    		
    	}
    	else if( diff > 2 ) {
    		alert( "This is NOT an INFANT \n they are older that 2" );
    		infant = false;
    		document.form.birthday.value = "";
    		document.form.date.focus();
    	}
    	
    }
    
    
    <form name="form" action="abc.htm">
    INF:<select name="date"
    onChange="document.form.birthday.value=document.form.birthday.value+document.form.date.options[document.form.date.selectedIndex].value;"
    style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
    <%
    	Response.write "<option> --- </option>"
    For d = 01 to 31
    	Response.write "<option value=" & d & "/>" & d & "</option>"
    Next
    %>
    </select>
    <select name="month"
    onChange="document.form.birthday.value=document.form.birthday.value+document.form.month.options[document.form.month.selectedIndex].value;"
    style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
    <%
    	Response.write "<option> --- </option>"
    For m = 01 to 12
    	response.Write "<option value=" & m & "/>" & MMtoMMM(m) & "</option>"
    Next
    %>		
    </select>
    <% 
    Dim three_years_ago
    three_years_ago = year(date) - 3
    %>
    <select name="year"
    onChange="document.form.birthday.value=document.form.birthday.value+document.form.year.options[document.form.year.selectedIndex].value;"
    style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
    <%
    	Response.write "<option> --- </option>"
    For y = three_years_ago to year(date)
    	Response.Write "<option value=" & y & ">" & y & "</option>"
    Next
    %>
    </select>
    
    <input type="text" name="birthday" size="5" style="font:7pt;" value="" maxLength="10"> 
    
    <img src="images/required.gif"  onclick="javascript: checkBirthday(document.form.birthday);" value="Confirm">
    </form>

  • #2
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    thats my asp function MMtoMMM

    Code:
    function MMtoMMM(Fdate)
    						Select Case Fdate
    						Case "1"  
     						 validdate = "JAN"
    						Case "2"  
    						 validdate = "FEB"
    						Case "3"  
    						 validdate = "MAR"									 			 
    						Case "4" 
    						 validdate = "APR"	
    						Case "5"  
    						 validdate = "MAY"						
    						Case "6"  
    						 validdate = "JUN"						
     						Case "7"  
    						 validdate = "JUL"			  
    						Case "8"  
    						 validdate = "AUG"				
     						Case "9"  
    						 validdate = "SEP"					 						 
    						Case "10"  
    						 validdate = "OCT"
    						Case "11"  
    						 validdate = "NOV"						
     						Case "12"  
    						 validdate = "DEC"	 
    						end select
    						MMtoMMM  = validdate
    						end function

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    has anyone got code to stop this?

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll get more responses if you just give the HTML and Javascript -- I read your first post a couple hours ago, encountered the asp, and clicked the back button.

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    sorry, i was just trying to give more info

  • #6
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    anyone got a work around for this?

  • #7
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #8
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    ?????

  • #9
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The function you want is the FIRST ONE "select_data", the other two i just use to ease up building the selects (which i use a lot)...

    if explanation needed, asdruble@hotmail.com - MSN

    function select_data(num,dia,mes,ano,tipo){
    day=eval('document.all.'+dia);
    mon=eval('document.all.'+mes);
    year=eval('document.all.'+ano);
    datebc=eval('document.all.'+tipo);

    switch (num){
    case 1:
    if (mon.value !=""){
    if (mon.value==2) select_data(3,dia,mes,ano,tipo);
    else select_data(2,dia,mes,ano,tipo);
    }
    break;
    case 2:
    if (mon.value == 2 && year.value != "" && day.value > 29) select_data(3,dia,mes,ano,tipo);
    if((mon.value == 4 || mon.value == 6 || mon.value == 9 || mon.value == 11) && day.value == 31){
    day.value=30;
    }
    break;
    case 3:
    if((day.value > 28 && mon.value == 2)){
    if(!((+(year.value)) % 400 == 0 || (+(year.value)) % 100 != 0 && (+(year.value)) % 4 == 0)){
    day.value=28;
    }else{
    day.value=29;
    }
    }
    default: break;
    }
    datebc.value = day.value+"/"+mon.value+"/"+year.value;
    }

    function data_escreve(act,marcado,inicio,fim){

    switch(act){
    case 1:
    for(i=1;i<32;i++){
    if (i==marcado)
    document.write('<option value="'+i+'" SELECTED>'+i+'</option>');
    else
    document.write('<option value="'+i+'">'+i+'</option>');
    }
    break;
    case 2:
    for(i=1;i<13;i++){
    if (i==marcado)
    document.write('<option value="'+i+'" SELECTED>'+i+'</option>');
    else
    document.write('<option value="'+i+'">'+i+'</option>');
    }
    break;
    case 3:
    for(i=inicio;i>fim;i--){
    if (i==marcado)
    document.write('<option value="'+i+'" SELECTED>'+i+'</option>');
    else
    document.write('<option value="'+i+'">'+i+'</option>');
    }
    break;
    }
    }

    //ESCREVE OS SELECTS PARA SELECIONAR DATA
    /*
    nome = nome do campo escondido (recebido pelo script)
    dia = nome do campo de DIA (unique)
    mes = nome do campo de MES (unique)
    ano = nome do campo de ANO (unique)
    sdia = preselecao do campo DIA
    smes = preselecao do campo MES
    sano = preselecao do campo ANO
    ano_atual = recebe data atual verdadeira do script
    valor = valor inicial do campo escondido ('SDIA/SMES/SANO')
    */
    function data_campos(nome,dia,mes,ano,sdia,smes,sano,ano_atual){

    var valor = (sdia+'/'+smes+'/'+sano);
    //HIDDEN
    document.write('<input type="hidden" name="'+nome+'" value="'+valor+'">');
    //DIA
    document.write('<select name="'+dia+'" class="select" onChange="select_data(1,\''+dia+'\',\''+mes+'\',\''+ano+'\',\''+nome+'\')">');
    document.write('<option value=""> Dia </option>');
    data_escreve(1,sdia);
    document.write('</select>&nbsp;');
    //MES
    document.write('<select name="'+mes+'" class="select" onChange="select_data(2,\''+dia+'\',\''+mes+'\',\''+ano+'\',\''+nome+'\')">');
    document.write('<option value=""> Mes </option>');
    data_escreve(2,smes);
    document.write('</select>&nbsp;');
    //ANO
    document.write('<select name="'+ano+'" class="select" onChange="select_data(3,\''+dia+'\',\''+mes+'\',\''+ano+'\',\''+nome+'\')">');
    document.write('<option value=""> Ano </option>');
    data_escreve(3,sano,ano_atual,ano_atual-106);
    document.write('</select>&nbsp;');
    //INICIA VALOR
    select_data(0,dia,mes,ano,nome)
    }

  • #10
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    forename = document.form.cfname[Math.floor(i+1)].value
    is this not valid JS? i is my control loop

  • #11
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    re your original question, surely you just want to clear the hidden field before adding the new values. no?!
    *keep it simple (TM)

  • #12
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    no i need to reference the field as clname1 for eg.

  • #13
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    do i not use '[' char?

  • #14
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    this is my javascript loop:

    Code:
    for (i=0; i<document.form.nochd.value-1; i++)
    	{
    	if( !/^(\d{1,2})(\d{1,2})(\d{4})$/.test(obj.value) ) {
    		alert( "Invalid date supplied - must be format DDMMYYYY" );
    		return;
    	}
    	
    	var d = new Date();
    	var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
    	nochd = document.form.nochd.value
    	noinf = document.form.noinf.value
    	
    	var diff = d.getDiff(d2, "y")
    
    	if( isNaN(diff) ) {
    		alert( "Invalid date supplied" );
    	}
    	else if( diff < 12 ) {
    		alert( "This IS an CHILD \n they are younger than 12" );
    		child = true;
    		submit_form=true;
    		under12counter = under12counter + 1;
    		passtocheckRetDate = obj.value;
    		checkRetDate(document.form.retdt);
    		
    	}
    	else if( diff > 12 ) {
    		alert( "This is NOT an CHILD\nthey are older than 12" );
    		child = false;
    		
    		submit_form=false;
    		chdcounter = chdcounter + 1; // amount of declared children that are found to be under 12
    		childno = i+1
    		
    		
    		number = parseFloat(i+1);
    		
    		
    		forename = document.form.cfname1.value
    		surname = document.form.clname1.value
    	
    		if(chdcounter==2)
    		{
    			forename2 = document.form.cfname2.value
    			surname2 = document.form.clname2.value
    		}
    		
    		if(chdcounter==3)
    		{
    			forename3 = document.form.cfname3.value
    			surname3 = document.form.clname3.value
    		}
    		
    		}
    	}
    I need to reference the correct form field by using the (control loop + 1). How can i build this
    into my JS?

    I have tried
    Code:
    forename = document.form.cfname[i+1].value
    surname = document.form.clname[i+1].value
    but it doesnt work. any ideas?

  • #15
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You can use this to set your variables within a lopp, it would produce variables of forename0, forename1, forename2, etc. If your form elements start cfname1 then start the loop from 1 rather than 0.

    Code:
    // change myFunctionName to whatever your function name is
    for( var i=0; document.form.elements["cfname"+i]; i++ ) {
    	myFunctionName["forename"+i] = document.form.elements["cfname"+i].value;
    }
    what are you doing with this information though? You already have the forenames nicely organised and easily referenced - why duplicate into variables?

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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