Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

simple javascript on text field

  • 21-02-2008 2:15pm
    #1
    Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭


    i'm doing a bit of javascript that's part of a cgi file that i need to have a text field that will contain a date 'YYYY-MM-DD' format and this date then needs to be stored in a cgi variable so that it can be passed to another cgi file.

    at the moment i have a text field that when you focus on it it pops up a little calendar so you can pick the date ie.
    my $myform = "
             <form>
                follow-up date:
                     <input type=\"text\" name=\"followupdate\" id=\"followupdate\" onfocus=\"showCalendarControl(this);\">
    

    that will work perfectly at displaying a box and when you click on it, a calendar pops up and when you select your date the date gets inputted into the text field in the format 'YYYY-MM-DD'.

    now i want to be able to extract that info, so that it can be stored in a perl variable.

    here's my javascript to get the date.
    function getFollowupDate()
        {
            var date = document.getElementById('followupdate');
            return date;
        }
    
    

    then to store it into a perl var.
    my $followupdate = "<script type=\"text/javascript\">getFollowupDate();</script>";
    

    then if i try to print it out i get nothing. anyone see where i'm going wrong?

    if a mod feels this is more of a programming issue can you please move it.

    thanks


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Use var date = document.getElementById('followupdate').value; to get the text inside the box rather than the box itself? Been a while since I played with Javascript, so could be completely wrong.


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    ok so i have my javascript embedded in my cgi file like this and changed the .value as aidan said but to no avail.
    my $Loggedin='
    	<script type=text/javascript>
    		function getFollowupDate()
    		{
    			alert("hey!");
    			var date = document.getElementById(\'followupdate\').value;
    			document.write(date);
    			return date;
    		}
    	</script>
    	
    	...
    	...
    	...
    	...
    
    	';
    

    this is the form now i added an onblur=\"getFollowupDate();\" the following code is still in the same perl var as above.
    	<form>
    		follow-up date:
    		<input type=\"text\" name=\"followup\" id=\"followupdate\" onfocus=\"showCalendarControl(this);\" onblur=\"getFollowupDate();\" value=\"\">
    	</form>
    

    so getFollowupDate() should be called when the text box loses focus because of the onblur and i see the alert box.

    is there any way to store what gets returned from getFollowupDate() into a perl variable.


  • Registered Users, Registered Users 2 Posts: 6,570 ✭✭✭daymobrew


    I can't help but feel that you are mixing up client and server side actions.

    You say that the date gets put into the text box after the popup is called. This textbox seems to be called 'followup'. So, in your perl CGI script:
    my $TheDateYouWant = param( 'followup' );
    

    Aside: it might be easier to put the Javascript in a separate file and simply include it in the HTML code. It will certainly reduce the amount of escaping of quotes you have to do.
    print $q->start_html(-title=>'Script Title', -script=>{-type=>'text/javascript', -src=>'/path/to/javascript/file.js'} );
    


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Yup as daymo said it's a problem with your understanding of the server-client model. Solution provided above will work and as suggested move the scripts out to a .js file then all you need to do is call the function.

    -RD


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    aye, got it now, i do have an external scripts file but i just put it in the cgi to test it was working first.

    thanks for your help guys.


  • Advertisement
Advertisement