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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help: Geting div value in form input

    Hello,

    I am developing an ecommerce site using simplecartjs.org, everything on that script works by div. I need to get product id, inside a div tag, in an input field.

    for example,

    Code:
    <div class="product_id" id="product_id1">0033456</div>
    in order to make payment page work i need to provide this product id on cart page and then post that id to payment page.

    is there any way i can get product id in input? e.g.

    please note that there can one or more <div> product_id. e.g. if user adds one product then there will be only one input. if user adds three products then there will be three input in form.

    Code:
    <input type="text" id="product_id1" value="0033456"/>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    <div class="product_id" id="product_id1">0033456</div>
    
    <script type = "text/javascript">
    
    var x = document.getElementById("product_id1").innerHTML;
    alert (x);
    
    </script>

    And it left Ambrose one-on-one with three United attackers. - Commentator Talksport

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok. thanks

    But how to put 0033456 in value in
    Code:
    <input type="text" id="product_id1" value=""/>
    ?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by kpmr View Post
    ok. thanks

    But how to put 0033456 in value in
    Code:
    <input type="text" id="product_id1" value=""/>
    ?
    You cannot have multiple elements with the same id. ids must be unique.

    Surely it is obvious?

    document.getElementById("fieldid").value = x;

    Code:
    <div class="product_id" id="product_id1">0033456</div>
    <input type="text" id="prod1" value=""/>
    
    <script type = "text/javascript">
    var d = document.getElementById("product_id1").id;
    //alert (d);
    var x = document.getElementById("product_id1").innerHTML;
    //alert (x);
    document.getElementById("prod1").value = x;
    
    </script>
    Last edited by Philip M; 05-08-2013 at 10:14 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,196
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Quote Originally Posted by kpmr View Post
    in order to make payment page work i need to provide this product id on cart page and then post that id to payment page.
    ...
    Code:
    <input type="text" id="product_id1" value="0033456"/>
    Ummm...I don't think so.

    An <input> field with only an ID will *NOT* be posted to ANY page.

    Only fields with *NAMES* are ever sent by HTML to another page.

    It would be okay for the form to have both and ID and a name:
    Code:
    <input type="text" id="product_id1" name="product_id1"/>
    But without the name the payment page will never see that field.

    FURTHER: It is illegal to have an ID repeated on a page, so *CLEARLY* you can not possibly have both
    Code:
    <div id="product_id1">
    and 
    <input id="product_id1">
    You need to show us what is *ACTUALLY* on your page. What you showed can't possibly ever work.

    **********
    please note that there can one or more <div> product_id. e.g. if user adds one product then there will be only one input. if user adds three products then there will be three input in form.
    So *ARE* there serveral <div>s? each with a different ID?
    If so, what *ARE* the different IDs?

    And do the multiple <input> fields already exist? Or is the code supposed to automatically create them?

    Philip has answered part of your question, but the question as you gave it is impossible. So if you really want help you need to show us your ACTUAL HTML CODE. All the <div>s. All the <input>s.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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