...

View Full Version : Taking Information from forms to change form value



Iceman Luch
12-16-2010, 06:43 PM
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="">

Philip M
12-16-2010, 07:38 PM
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.

Iceman Luch
12-16-2010, 08:38 PM
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.

Philip M
12-17-2010, 08:30 AM
You have two elements with the same id custMes.

Your form name is custPrice, not price.


<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>

Iceman Luch
12-17-2010, 03:01 PM
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>

Iceman Luch
12-17-2010, 03:03 PM
This the beginning of the form that contains the radio buttons.

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

Philip M
12-17-2010, 03:29 PM
Study the code I gave you. And use some alerts to check if the radio button values are correct.

Iceman Luch
12-17-2010, 04:13 PM
Okay will do and will let you know how that goes.

Thanks

Iceman Luch
12-17-2010, 10:22 PM
I finally figured it out and it is working perfectly!!!



<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum