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.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Taking Information from forms to change form value

    I am creating a website for someone and can get information from one form to check it so it can then change the data in another form.

    This what I have for JavaScript:
    <script type="text/javascript" language="JavaScript">
    function price()
    {
    if(document.cust.top.value == None &&
    document.cust.swirl.value == None)
    {
    document.price.hosted_button_id.value =
    "UDNNKUHTPGEEW";
    }
    else
    {
    document.price.hosted_button_id.value =
    "CP8EVFLEASF28";
    }
    }
    </script>

    The result I want is to take the value from my form that has a radio buttons and check to see if it equal none or not. Then using that information change the value in a different form.

    The first form looks like this for beginning:
    <form name="cust" method="get" action="">
    Last edited by Iceman Luch; 12-16-2010 at 07:03 PM. Reason: I edited to show changes I tried making.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    If the different form is not on the same page then you will need to pass the value using a cookie or a query string.

    If it is in the same page you can refer to the forms by name or by document.forms[0].

    function price() - you may not give the same name to a JavaScript function and a form element.

    You need to look again at how to get the value of a checked radio button.

    "Come and catch up with your camp friends and introduce new families to the wonders of a Miniwanca summer"
    American Youth Foundation, Cleveland area Miniwanca party.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I changed the function name so that is not not the same as the form name. The two forms are on the same page.

    script type="text/javascript" language="JavaScript">
    function cheesecake()
    {
    if(cust.top.topnone.checked == true &&
    cust.swirl.swnone.checked == true)
    {
    price.hosted_button_id.value =
    "UDNNKUHTPGEEW";
    }
    else
    {
    price.hosted_button_id.value =
    "CP8EVFLEASF28";
    }
    }
    </script>

    This is the second form:

    <form name="custPrice" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
    <input type="hidden" name="cmd" value="_s-xclick" />
    <input type="hidden" name="hosted_button_id" value= "G4W5QGQKY3CDN"/>
    <table>
    <tr>
    <td><div id="custMes"><input type="hidden" name="on0"
    value="Custom Message" />Custom Message</div></td>
    </tr>
    <tr>
    <td><div id="custMes"><input type="text" name="os0"
    maxlength="60" /></div></td>
    <td><div id="addCart"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" onclick="cheesecake()"/></div>
    <img src="https://www.paypal.com/en_US/i/scr/pixel.gif" alt="" border="0" width="1" height="1" /></td>
    </tr>
    </table>
    </form>

    The value in the below part is what needs to be changed by the JavaScript.
    <input type="hidden" name="hosted_button_id" value= "G4W5QGQKY3CDN"/>

    I believe that I have it right how to check radio button in JavaScript. I could be wrong though.
    Last edited by Iceman Luch; 12-16-2010 at 08:40 PM. Reason: Wanted to add something.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    You have two elements with the same id custMes.

    Your form name is custPrice, not price.

    Code:
    <script type="text/javascript">
    function cheesecake() {
    if (document.cust.top.topnone.checked == true && document.cust.swirl.swnone.checked == true){
    document.custPrice.hosted_button_id.value = "UDNNKUHTPGEEW";
    }
    else {
    document.custPrice.hosted_button_id.value = "CP8EVFLEASF28";
    }
    }
    </script>
    Last edited by Philip M; 12-17-2010 at 03:31 PM.

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I realized the custMes id thing yesterday and met to make it a class. That is done and looks good.

    I did change the price to custPrice but did not fix it here oops.

    I added <label> </label> to the radio buttons.

    However it is still not working. I personally think that it is not getting the radio button information right.

    <link rel="stylesheet" href="Cheesecakes.css" type="text/css" />
    <script type="text/javascript" language="JavaScript">
    function cheesecake()
    {
    if(cust.top.topnone.checked == true &&
    cust.swirl.swnone.checked == true)
    {
    CustPrice.hosted_button_id.value =
    "UDNNKUHTPGEEW";
    }
    else
    {
    CustPrice.hosted_button_id.value =
    "CP8EVFLEASF28";
    }
    }
    </script>

    <form name="custPrice" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
    <input type="hidden" name="cmd" value="_s-xclick" />
    <input type="hidden" name="hosted_button_id" value= "G4W5QGQKY3CDN"/>
    <table>
    <tr>
    <td><div class="custMes"><input type="hidden" name="on0" value="Custom Message" />Custom Message</div></td>
    </tr>
    <tr>
    <td><div class="custMes"><input type="text" name="os0" maxlength="60" /></div></td>
    <td><div class="addCart"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!"
    onclick="cheesecake()"/></div>
    <img src="https://www.paypal.com/en_US/i/scr/pixel.gif" alt="" border="0" width="1" height="1" /></td>
    </tr>
    </table>
    </form>

  • #6
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This the beginning of the form that contains the radio buttons.

    <form name="cust" method="get" action="">

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    Study the code I gave you. And use some alerts to check if the radio button values are correct.

  • Users who have thanked Philip M for this post:

    Iceman Luch (12-17-2010)

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay will do and will let you know how that goes.

    Thanks

  • #9
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I finally figured it out and it is working perfectly!!!

    Code:
    <script type="text/javascript" language="JavaScript">
    		function cheesecake()
    		{
    
    			for (var i=0; i < document.orderform.top.length; i++)
    			   {
    			   if (document.orderform.top[i].checked)
    				  {
    				 	 var topping = document.orderform.top[i].value;
    				  }
    			   }
    
    			for (var i=0; i < document.orderform.swirl.length; i++)
    			   {
    			   if (document.orderform.swirl[i].checked)
    				  {
    				 	 var inside = document.orderform.swirl[i].value;
    				  }
    			   }
    
    			if (topping == "None" && inside == "None")
    				{
    					document.cust.hosted_button_id.value = "UDNNKUHTPGEEW";
    				}
    			else
    				{
    					document.cust.hosted_button_id.value = "CP8EVFLEASF28";
    				}
    		}
    	//-->
    	</script>


  •  

    Posting Permissions

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