SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to pass form values to another page. javascript

    I have a form with allot of form items on it that posts to itself. I am trying to pass those form values to another page with out using the action attribute in the form. Is there a way to do this? I have tried jquery and javascript but coming up blank. Just trying to pass all the values at one time to another page. Seems a little difficult to me since im a intermediate javascript programmer. Any ideas are welcome and thank you in advance if someone knows how to get this going.

    Here is what i am trying to do script wise.

    theform is the ID of the form. I have a switch statement that is based on the button pressed would get into that statement. So if one of the three buttons on the page is "excel report" it should get into that statement and pass the values of the form to another page.

    I have tried this:

    Code:
    <cfswitch expression="#LCase(Trim(FORM.submit))#"> 
    	   <cfcase value="Excel Report">
    		   	<script>
    		   		function formSubmit() {
    					var form = document.forms.theForm;
    					// change the url
    					form.action ="index.cfm?keyword=Report PDF New";   
    					form.submit();  
    						}
                         </script>
              </cfcase>
    </cfswitch>
    AND This

    Code:
    <cfswitch expression="#LCase(Trim(FORM.submit))#"> 
              <cfcase value="PDF Report">
    		<script>
    			$('##submit').click(function(){
    				open('',"results");
    				with(document.print)
    				{
    				method = "POST";
    				action = "index.cfm?keyword=Report PDF New";
    				target = "results";
    				submit();
    				}
    				});
    		</script>
    	   </cfcase>
    </cfswitch>
    neither work.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,717
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dolla2 View Post
    I have a form with allot of form items on it that posts to itself. I am trying to pass those form values to another page with out using the action attribute in the form.
    Very little of cold fusion is known of here, but the typical way of achieving your end result is to use hidden form controls within the form itself, to store the data you wish to pass on.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply I greatly appreciate it , but what I am looking for is the javascript that would enable me to pass variable on to the next page. I some what did it with the following script but dont know if its write or not. here is a peak.

    Code:
    <script language="javascript">
    	function sendFormExcel(form){
    		var sel = form.ToLB;
    		for ( var i = 0; i < sel.options.length; ++i ) 
    		{
    			 sel.options[i].selected = true;
    			}
    		if ( document.theForm.ToLB.value == "" ) 
    		{
    		  alert ( "Please select items from the list box. " );
    		  return false;
    		}
    		document.theform.action = 'index.cfm?keyword=Contract Report Excel';
    		return true;
    	}
    	</script>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,717
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dolla2 View Post
    I some what did it
    What do you mean by "some what"? I won't even ask about write or peak.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was trying to pass the form data from the page to another page by using the dynamic form attribute and for some reason the prevoious script is not going to that page. What I meant by somewhat is that the previous script is what I am looking to do but its not redirecting to the other page. Am i doing something wrong in this script. I even tried it by ID.

    <script language="javascript">
    function sendFormpdf(form){
    var sel = form.ToLB;
    for ( var i = 0; i < sel.options.length; ++i )
    {
    sel.options[i].selected = true;
    }
    if ( document.theForm.ToLB.value == "" )
    {
    alert ( "Please select from the list box. ");
    return false;
    } document.getElementByID(theForm).action="index.cfm?keyword=Contract Report PDF";
    }
    </script>

  6. #6
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so I fixed the script so that when someone submits a form it should redirect to the new page. Now my problem is another srcript that when someone selects too many list items it should validate. This is not working for some reason. In advance thanks to whoever helps me fix this I greatly appreciate it.

    The Script:

    Code:
    <script language="javascript">
    	function sendForm(form){
    	var sel = form.ToLB;
    	for ( var i = 0; i < sel.options.length; ++i ) 
    	{
    	sel.options[i].selected = true;
    					}
    	if ( document.theForm.ToLB.value == "" ) 
    	{
    	alert ( "Please select an item from the list box. " );
    	return false;
    	}
    	if(!sel.options[i].selected.length <10){
    	alert("Sorry! You can only select up to 10 list items for the html view!");
    	return false;
    	}
    }
    </script>


Bookmarks

Posting Permissions

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