www.webdeveloper.com
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 48

Thread: [RESOLVED] Passing Variables between pages

  1. #1
    Join Date
    Nov 2008
    Posts
    30

    resolved [RESOLVED] Passing Variables between pages



    I am having trouble with the coding for passing. I have tried various coding suggestions, but none of them seem to work with what I need. Below is the form of the parent page. This is part of a table that lists several files. The form is a request of a file. I only show one variable that is maincategory and the name will change depending on the request. There is a form button like this for every file. This is the set up that has been part of my company and I can't change that. I am just adding the form request as a convenience rather than just asking through e-mail.

    <td><FORM METHOD="LINK" Name="varpass" ACTION="childpg_Form.html" onclick="open_win()">
    <input type="button" name="DLForm" value=" FORM " maincategory="name" ></td></Form>

    Everything works going from the parent to the child, except for passing the variables. There will be three variables for each button, and I need to change the "name" for each variable to be passed to the next page and to go in to the form. The three variables are maincategory, subcategory, and filename

    Here is the form code:

    <form method="post" action="mailto:my_email?subject=Data Library request/comment"

    enctype="text/plain" onsubmit="return checkData()" NAME="Info" onreset="Close_win()">
    <br>&nbsp;<br>
    Date: <input type="text" name="date" size="20">
    <br>&nbsp;<br>
    Name:
    <input type="text" name="name" size="50">
    <br>&nbsp;<br>
    E-mail:
    <input type="text" name="email" size="50">
    <br>&nbsp;<br>
    Main Category:
    <input type="text" name="maincategory" size="50" value="">
    <br>&nbsp;<br>
    Sub Category:
    <input type="text" name="subcategory" size="50" value=>
    <br>&nbsp;<br>
    File Name:
    <input type="text" name="filename" size="50" value=>
    <br>&nbsp;<br>
    <input type="radio" name="request/comment" value="request" checked="true"> Request
    <br>&nbsp;<br>
    <input type="radio" name="request/comment" value="comment"> Comment
    <br>&nbsp;<br>
    Please give a brief description of your request or comment.
    <br>&nbsp;<br>
    <textarea type="text" name="request/comment-text" size="250" cols="50" rows="15"></textarea>
    <br>&nbsp;<br>
    <input type="submit" value="Send"><input type="reset" value="Reset">
    <br>&nbsp;<br>
    The reset button will close the form.
    <br>&nbsp;<br>
    <br>&nbsp;<br>
    </form>

    This is becoming a real puzzler to me

  2. #2
    Join Date
    Feb 2008
    Posts
    1,666
    This requires an email client on the user's local PC which can handle the submitted format:

    action="mailto:my_email?subject=Data Library request/comment"

    99&#37; of email clients on the user's local PC *CANNOT* handle the submitted format! This is why it is always the standard advice to use server-side code for sending emails from a web browser.

  3. #3
    Join Date
    Nov 2008
    Posts
    30

    Unhappy I am not having a problem with sending through e-mail

    My problem isn't with the child for with sending to my e-mail. It is with the parent sending the variables. I just showed the form of the child page to show where I need to send the variables. I am trying to figure out the right function JavaScript to send my variables to the child form. The child form action is a separate action and it works. I really need help with passing variables from the parent to child.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,666
    Well, in the first place, there is no such thing in HTML as a FORM METHOD of LINK. There is only GET and POST. Now, in AJAX, I know you can use a HEAD request and some claim you can use a PUT request but, in HTML, there is only GET and POST. Have you got that straight? That is the most important thing to get through your head no matter what you might read elsewhere.

    So, barring the use of server-side code, the submitting (what you call, "parent") page can use METHOD=GET to submit the values from the form elements as a query string attachment to the url specified in the ACTION attribute of the FORM. Have you got that straight? Change your METHOD to GET.

    Then, in the receiving (what you call, "child") page, you can parse the content of this property to get the values passed to the second page:

    alert(top.location.search);

    Show me you can get that far. Then I can give you more if you want it.

  5. #5
    Join Date
    Nov 2008
    Posts
    30
    I received the alert box when going to the other page. I also used the GET method first, but it didn't work with the function example I was using. I have tried many methods and functions, but none have them worked. I have a lot more coding on my pages that work also, so I understand what you are saying, I have only showed in my example the parts that I need to pass the variable to and from. Yes, I would like the rest of the code for passing the variables. I would really appreciate the help, which pertains more to my situation, since the other examples I have found don't seem to work.

    I got the Method Link from someone else's example, and it worked for their example, but it didn’t for what I needed.

    Thank you for your help. I really appreciate it.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,666
    Quote Originally Posted by MrNobody View Post
    Then, in the receiving (what you call, "child") page, you can parse the content of this property to get the values passed to the second page:

    alert(top.location.search);

    Show me you can get that far. Then I can give you more if you want it.
    Show me what you got in the receiving page -- in the alert.

  7. #7
    Join Date
    Nov 2008
    Posts
    30
    This is all I have, and I get an alert window, but the content parse is the part I am having trouble with. The variables are (maincategory, subcategory, and filename). The values within will change pertaining the form request button from the parent.

    Parent:

    <td><FORM METHOD="GET" Name="varpass" ACTION="childpg_Form.html" onclick="open_win()">
    <input type="button" name="DLForm" value=" FORM " maincategory="name" ></td></Form>


    When you said "to submit the values from the form elements as a query string attachment to the url specified in the ACTION attribute of the FORM." I understand what you are saying here, but I need to know what the wording would be for my specific situation.

    Child (or childpg_Form.html as it is referred to in the the ACTION of the FORM)

    <script type ="text/javascript">

    <!-- hide

    alert(top.location.search);


    // -->


    </script>

    Thank you for your help.

  8. #8
    Join Date
    Feb 2008
    Posts
    1,666
    Quote Originally Posted by sidDev View Post
    This is all I have, and I get an alert window, but the content parse is the part I am having trouble with.
    I'm going to give you the content parsing function. But I want to see the actual content you're getting in the alert, first. It doesn't matter if it changes for various situations. I just want to see the alert content to confirm that you are seeing what you should be seeing.

  9. #9
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    When I create demos for clients and need to "fake" a form submit when I do not have server side access I use javascript to retreive the name/value pair values on the receiving page using the following 3 functions:

    Code:
    //////////////////////////////////////////////////////////////////////////////
    // getParameter 
    //
    //		If page was called as an action from a form post (method="get") then
    //		get the value of the parameter "paramName" from the name/value parirs
    //		in the current URL
    //						
    //  @param   paramName - name of parameter to retreive value of
    //  @return  returnValue - value of parameter extracted from location.href
    //////////////////////////////////////////////////////////////////////////////
    function getParameter(paramName) {
    
    	// Build regex expression to find paramName in window.location.href
    	// and then parse out everything after the "=" sign and before the "&"
    	// sign
    	paramName = paramName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    	var regexS = "[\\?&]"+paramName+"=([^&#]*)";
    	var regex = new RegExp( regexS );
    	var results = regex.exec( window.location.href );
    
    	if( results == null )
    		return "";
    	else {
    		returnValue = unescape(results[1]);		// Unescape it
    		returnValue = returnValue.replace(/\+/g, ' ');	// Replace plus sign with space
    		return returnValue;
    	}
    }
    
    //////////////////////////////////////////////////////////////////////////////
    // showParameter 
    //
    //		Display the results of the getParameter function at the current 
    //		location in the document body.
    //						
    //  @param   paramName	- name of parameter to retreive value of
    //  @return  paramValue	- value of paramter written to the document.
    //////////////////////////////////////////////////////////////////////////////
    function showParameter(paramName) {
    	// If object exists on page with the same ID as the param name then 
    	// copy set its value to the parameter value
    	copyParameterValue(paramName);
    
    	var paramValue = getParameter(paramName);	// Get parameter value
    	document.write(paramValue);			// Write to document
    }
    
    
    function copyParameterValue(paramName) {
    	var paramValue = getParameter(paramName);
    	if (document.getElementById(paramName) != null) {
    		document.getElementById(paramName).value = paramValue;
    	}
    }
    You can then use it in a page like this:
    Code:
    <div id="farwellMsg">
    	You <script>showParameter("status");</script> in completing the form.  
    	Thank you <script>showParameter("userName");</script>
    </div>

  10. #10
    Join Date
    Nov 2008
    Posts
    30
    I will send an attachment.

  11. #11
    Join Date
    Nov 2008
    Posts
    30

    Alert Window

    Here is the alert window attachment MrNobody:
    Attached Files Attached Files

  12. #12
    Join Date
    Nov 2008
    Posts
    30
    Thank you, but I don't think this is where my problem is. I am not having problems with my form submittal. It is bringing in the variables form the main page to my form on the second page. The Form on the main page is just the input button to carry the variables. I have tried codes similar to this without it working, because I need it to go into text boxes in the form on the second page. I will try this code pseudo situation without all of my other coding that are on my pages to see if it works.

  13. #13
    Join Date
    Feb 2008
    Posts
    1,666
    OK, so you're alert is blank. Then you have a problem with your submittal or you've placed the alert in the wrong page (not the receiving page).

  14. #14
    Join Date
    Nov 2008
    Posts
    30
    Do you have any idea what it is?

  15. #15
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Quote Originally Posted by sidDev View Post
    ... It is bringing in the variables form the main page to my form on the second page...
    That is what "copyParameterValue" does.

    Just have the form elements on the page with an id assigned to them.

    Example:
    Code:
    <form ....>
    	<input type="text" name="status" id="status" value="" />
    	<script>copyParameter("status");</script>
    
    	<input type="text" name="userName" id="userName" value="" />
    	<script>copyParameter("userName");</script>
    </form>
    I use showParameter when I want to display them as text on the page and additionally shove them into a hidden form field to pass on to a third page.
    Last edited by slaughters; 11-21-2008 at 12:07 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles