70470 Posts in 6879 Topics - by 687 Members - Latest Member: Laricwashere

Author Topic: Javascript/HTML help needed  (Read 1669 times)

Offline Czar

  • Event Administrator
  • Sponsorship Coordinator
  • Godlike Gamer
  • *
  • Posts: 4632
  • Karma: 11
  • Steam ID: therealdealmobile@hotmail.com
  • XBox Gamer Tag: IAmCzarAlex
  • XFire: czaralex
Javascript/HTML help needed
« on: August 25, 2008, 08:07:33 AM »
Here's the dizzle. I'm trying to add a PayPal shopping cart to my chainmaille website. I've done this before, years ago, for a different side business but this time, I need to modify some code so the buyer can specify more options.

Code: [Select]
<input name="item_number" type="radio" value="15 dice">When the above radio button is checked, it changes the Item Number variable to "15 dice"

At the same time, I would also like the code to update the cost of a 15 dice capacity dice bag
Code: [Select]
<input type="hidden" name="amount" value="10.00">
..How can I get TWO variables to be updated at once using only the one radio button? There are other radio buttons used, each with different dice capacities and each has an associated `amount` value. For example, a 30 count bag would be $20.

Suggestions?

Offline The Shoctor

  • Administrator
  • Godlike Gamer
  • *
  • Posts: 5803
  • Karma: 17
  • Steam ID: shadohawk@shadoworks.net
  • XBox Gamer Tag: TheShoctor
  • XFire: shadoworks
Re: Javascript/HTML help needed
« Reply #1 on: August 25, 2008, 08:23:06 AM »
Wouldn't the item look more like:
Code: [Select]
<input name="15_dice" type="radio" value="10.00">That way you just have to select the number of them you want?

Also, if you want to setup WordPress there is a shopping module addon that is free and can process paypal.

Support LAN Play!
ლ(ಠ益ಠლ) "I have more than 20 friends EA!" --FITES.NET
(╯°□°)╯︵ ┻━┻
"Close enough." --UGC League

Offline Czar

  • Event Administrator
  • Sponsorship Coordinator
  • Godlike Gamer
  • *
  • Posts: 4632
  • Karma: 11
  • Steam ID: therealdealmobile@hotmail.com
  • XBox Gamer Tag: IAmCzarAlex
  • XFire: czaralex
Re: Javascript/HTML help needed
« Reply #2 on: August 25, 2008, 08:33:17 AM »
Yes. but paypal's shopping cart won't process it using the "15_dice" name as its not one of the fields the paypal button jobbie looks for to process.. The item number will show the buyer what size bag they are ordering. The `amount` variable tells paypal how much to charge.

Here is the prototype page I designed with the required fields.


And the way it looks on the PayPal cart. Note the Price for a 30 count bag is $20, not $10. That's the
other field I need to change along with the Item#


Hmm.. wordpress eh? I've set that up before, so I know its not a pain, but I'm not sure how to turn it in to something that isn't wordpress looking. Know what I mean? (and I need this done by Wed night)

Offline The Shoctor

  • Administrator
  • Godlike Gamer
  • *
  • Posts: 5803
  • Karma: 17
  • Steam ID: shadohawk@shadoworks.net
  • XBox Gamer Tag: TheShoctor
  • XFire: shadoworks
Re: Javascript/HTML help needed
« Reply #3 on: August 25, 2008, 09:41:22 AM »
http://www.zabsart.com/
Still not done, but that is like 1 hour of work.
As for the javascript. Let me see what I can do when I get home from the office.

Support LAN Play!
ლ(ಠ益ಠლ) "I have more than 20 friends EA!" --FITES.NET
(╯°□°)╯︵ ┻━┻
"Close enough." --UGC League

Offline _!Rathe!_

  • Master Sergeant Shooter Sergeant Person
  • Godlike Gamer
  • *
  • Posts: 2296
  • Karma: 0
  • XFire: rathewin2k
Re: Javascript/HTML help needed
« Reply #4 on: August 25, 2008, 09:43:25 AM »
I don't believe there is a way to update 2 variables with one radio button.  I think the way to get the feature you want is  to do a bit of back end processing when you submit the form and adjust the price based on the size they select.  
Never, but never question the engineers judgement.

Offline Czar

  • Event Administrator
  • Sponsorship Coordinator
  • Godlike Gamer
  • *
  • Posts: 4632
  • Karma: 11
  • Steam ID: therealdealmobile@hotmail.com
  • XBox Gamer Tag: IAmCzarAlex
  • XFire: czaralex
Re: Javascript/HTML help needed
« Reply #5 on: August 25, 2008, 09:48:59 AM »
I hit some a javascript chan on IRC and someone suggested I catch the input before its sent to paypal and add the extra value. here's what I came up with:

Code: [Select]
<SCRIPT FOR="cmdsubmit" EVENT="onclick" LANGUAGE="JavaScript">
<!--
var TheForm;
TheForm = document.orderform;

if (TheForm.item_number.value == "30 dice") {
TheForm.amount.value = "20.00";
}
// -->
</SCRIPT>

But it doesn't seem to be tripping that if statement...or anything else I put in there for that matter. I named the form `orderform` and renamed the submit button to cmdsubmit

Offline _!Rathe!_

  • Master Sergeant Shooter Sergeant Person
  • Godlike Gamer
  • *
  • Posts: 2296
  • Karma: 0
  • XFire: rathewin2k
Re: Javascript/HTML help needed
« Reply #6 on: August 25, 2008, 10:31:16 AM »
I hit some a javascript chan on IRC and someone suggested I catch the input before its sent to paypal and add the extra value. here's what I came up with:

Code: [Select]
<SCRIPT FOR="cmdsubmit" EVENT="onclick" LANGUAGE="JavaScript">
<!--
var TheForm;
TheForm = document.orderform;

if (TheForm.item_number.value == "30 dice") {
TheForm.amount.value = "20.00";
}
// -->
</SCRIPT>

But it doesn't seem to be tripping that if statement...or anything else I put in there for that matter. I named the form `orderform` and renamed the submit button to cmdsubmit

Wouldn't the TheForm.item_number.value == "30 dice" part need to be 30_dice??
Never, but never question the engineers judgement.

Offline Czar

  • Event Administrator
  • Sponsorship Coordinator
  • Godlike Gamer
  • *
  • Posts: 4632
  • Karma: 11
  • Steam ID: therealdealmobile@hotmail.com
  • XBox Gamer Tag: IAmCzarAlex
  • XFire: czaralex
Re: Javascript/HTML help needed
« Reply #7 on: August 25, 2008, 10:31:55 AM »
I tried that combination too with no change.

Offline The Shoctor

  • Administrator
  • Godlike Gamer
  • *
  • Posts: 5803
  • Karma: 17
  • Steam ID: shadohawk@shadoworks.net
  • XBox Gamer Tag: TheShoctor
  • XFire: shadoworks
Re: Javascript/HTML help needed
« Reply #8 on: August 25, 2008, 12:39:06 PM »
Code: [Select]
<script>
function updateCost(item)
{

if (item=="15_Dice")
            {
              <<FORMNAME>>.ammount.value = "10.0";
            }
       
}
</script>

<input name="item_number" type="radio" value="15 dice" onclick='updateCost(15_Dice);'>

<input type="hidden" name="amount">



That should work for you... I can't test it where I am now. Let me know how it goes.

PS I forgot you have to change <<FORMNAME>> to the name tag of your form. :)
So the syntax for the update is <<formname>>.<<inputname>>.value
You could then add an if for each you want to do.
« Last Edit: August 25, 2008, 12:40:55 PM by The Doctor »

Support LAN Play!
ლ(ಠ益ಠლ) "I have more than 20 friends EA!" --FITES.NET
(╯°□°)╯︵ ┻━┻
"Close enough." --UGC League

Offline Czar

  • Event Administrator
  • Sponsorship Coordinator
  • Godlike Gamer
  • *
  • Posts: 4632
  • Karma: 11
  • Steam ID: therealdealmobile@hotmail.com
  • XBox Gamer Tag: IAmCzarAlex
  • XFire: czaralex
Re: Javascript/HTML help needed
« Reply #9 on: August 25, 2008, 01:31:46 PM »
I had to make a couple minor changes to the code but it works perfectly! Thank you!