8 Replies - 556 Views - Last Post: 20 July 2014 - 03:37 AM

#1 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 06:25 PM

Basically I have a dropdown box and depending on the value, I want a different value assigned to a form element. I've tried javascript but doesn't seem to work. I'm a C++ / Obj-C programmer... not so much into the web. I'm sure this is really basic but could someone help?

<script>
function getValue() {
    return document.getElementById("size").value;
}
</script>

<form action="http://shopsite.ipage.com/ss11.2/sc/order.cgi" method="post">
</br>
Size*
</br>
<select name="Size" id="size">
   <option value="74946968-0fa3-11e4-9bb8-00219b8b13ea">Jar</option>
   <option value="e96a46c2-0fa3-11e4-ac8f-00219b8b13ea">Pallet</option>
</select>
</br>
</br>
   <input type=hidden name="storeid" value="*186400997a4f89897978ac3250e3">
   <input type=hidden name="dbname" value="products">
   <input type=hidden name="function" value="add">
   <input type=hidden name="guid" value="getValue()">
   <input type=image src="https://shopsite.ipage.com/ss11.2/shopsite-images/en-CA/buttons/elite_silver_001/elite_silver_001_pr_add_to_cart.gif" hspace=3 vspace=3 border="0" align="bottom" alt="Add to Cart" name="Add to Cart">
   <input type=image src="https://shopsite.ipage.com/ss11.2/shopsite-images/en-CA/buttons/elite_silver_001/elite_silver_001_pr_view_cart.gif" hspace=3 vspace=3 border="0" align="bottom" alt="View Cart" name="View Cart">
</form>



The problem is that my Add to cart button thinks the value for my SKU is "getValue()"! I've also tried (line 20)
value = getValue()
without the ""... no help... I just don't get web programming :(/>/>/>

Thanks!

This post has been edited by lifeinbinary: 19 July 2014 - 06:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need to use the value from a dropdown box as the value for another val

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 674
  • View blog
  • Posts: 2,972
  • Joined: 03-December 12

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:04 PM

Let me ask what server side language you are using. With Javascript, you can add the value based on the change event of the dropdown list. But, depending upon what server side language you are using, you could directly get the value of the select from the name without using a hidden field.
Was This Post Helpful? 0
  • +
  • -

#3 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:14 PM

I really don't know... I'm building a site with Weebly Drag-n-Drop Site Builder and I threw in an "embed code" element (as opposed to a text element or an image element). An imbed code element allows me to write my own code instead of using their pre-made elements. So again... I don't know. I can try two different things :)
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 674
  • View blog
  • Posts: 2,972
  • Joined: 03-December 12

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:28 PM

Would this site be a production code level store front or a 'learning web development' practice level?
Was This Post Helpful? 0
  • +
  • -

#5 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:35 PM

Production I guess... It's my website hosted on iPage... They use Drag-n-Drop site Builder among other choices for development like Joomla etc... I chose Drag-n-Drop for the simplicity but needed to do something out of the box thus the question :)
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 674
  • View blog
  • Posts: 2,972
  • Joined: 03-December 12

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:44 PM

Unless you really want to learn web development, and if that is the case a production ecommerce site is not the first project I would recommend, I would go with an ecommerce CMS. Then you can tinker with the themes, plugins, and other items. It's like building an OS as your first C program. Yeah, you might make it work, but it is going to be really sensitive in what does work and what will bring it down.
Was This Post Helpful? 0
  • +
  • -

#7 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Re: Need to use the value from a dropdown box as the value for another val

Posted 19 July 2014 - 07:52 PM

Ok.. I'll take that into consideration, but could you tell me how to do what I asked? Please :)
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 674
  • View blog
  • Posts: 2,972
  • Joined: 03-December 12

Re: Need to use the value from a dropdown box as the value for another val

Posted 20 July 2014 - 12:16 AM

What I'm saying is, this

<input type=hidden name="guid" value="getValue()">


Is pointless, because you can already get the size by using that name"Size"
But,

11 <select name="Size" id="size" onchange="getValue()">

function getValue(){
   document.getElementsByName("guid").value = document.getElementsByName("Size").value;
}

This post has been edited by astonecipher: 20 July 2014 - 12:54 AM

Was This Post Helpful? 1
  • +
  • -

#9 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,875
  • Joined: 12-December 12

Re: Need to use the value from a dropdown box as the value for another val

Posted 20 July 2014 - 03:37 AM

getElementsByName returns a collection (a node-list), so:
document.getElementsByName("Size")[0].value;

but the element has an id so it is better to just use that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1