Web Analytics Made Easy -
StatCounter Forms with increment function - CodingForum

Announcement

Collapse
No announcement yet.

Forms with increment function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forms with increment function

    Hello to CodingForum,
    This is my beginning posting here as I am mostly reading, compiling and so..
    There are multiple forms in the script generated page, that has to update via script url - and the problem is probably looping through form script
    -so please help with this as only first form submit correctly while other pass value from 1st - need looping method or condition?
    Code:
    <SCRIPT language=Javascript>
    function getMessage(hwm)
    {	loc = './index.php?p=ordersBasket&sOption=add';
    	jlc = document.getElementById('qty');
    	jloc = document.getElementById('pid');
    	nloc = loc+ '&iProduct='+jloc.value+ '&iQuantity='+jlc.value;
    	self.location = nloc;
    }
    </SCRIPT>
    <FORM id="123" name="123">
    <input type="button" id="minus" value="-" onClick="qty.value = (qty.value-1)">
    <input type="button" value="+" onClick="qty.value = (+qty.value+1)">
    <input type="text" size="4" id="qty" name="name" value="3" />
    <INPUT TYPE="text" id="pid" VALUE="123" />
    <INPUT TYPE="button" value="order" onclick="getMessage(this)">
    </FORM>
    <FORM id="456" name="456">
    <input type="button" id="minus" value="-" onClick="qty.value = (qty.value-1)">
    <input type="button" value="+" onClick="qty.value = (+qty.value+1)">
    <input type="text" size="4" id="qty" name="name" value="3" />
    <INPUT TYPE="text" id="pid" VALUE="456" />
    <INPUT TYPE="button" value="order" onclick="getMessage(this)">
    </FORM>
    <FORM id="789" name="789">
    <input type="button" id="minus" value="-" onClick="qty.value = (qty.value-1)">
    <input type="button" value="+" onClick="qty.value = (+qty.value+1)">
    <input type="text" size="4" id="qty" name="name" value="3" />
    <INPUT TYPE="text" id="pid" VALUE="789" />
    <INPUT TYPE="button" value="order" onclick="getMessage(this)">
    </FORM>

  • #2
    Well, it's really a kind of bad idea to have more than one <form> on a page.

    But I don't see why you need *ANY* javascript here at all, if you created the <form>s correctly.

    Code:
    <form action="./index.php" method="get">
    <input type="hidden" name="p" value="OrdersBasket"/>
    <input type="hidden" name="sOption" value="add" />
    <input type="button" value="-" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)-1;" />>
    <input type="button" value="+" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)+1;" />>
    <input type="text" name="iQuantity" size="4" value="3" />
    <input type="text" name="iProduct" readonly="readonly" value="123" />
    <input type="submit" value="order"/>
    </form>
    <form action="./index.php" method="get">
    <input type="hidden" name="p" value="OrdersBasket"/>
    <input type="hidden" name="sOption" value="add" />
    <input type="button" value="-" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)-1;" />>
    <input type="button" value="+" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)+1;" />>
    <input type="text" name="iQuantity" size="4" value="3" />
    <input type="text" name="iProduct" readonly="readonly" value="456" />
    <input type="submit" value="order"/>
    </form>
    <form action="./index.php" method="get">
    <input type="hidden" name="p" value="OrdersBasket"/>
    <input type="hidden" name="sOption" value="add" />
    <input type="button" value="-" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)-1;" />>
    <input type="button" value="+" onClick="this.form.iQuantity.value = Number(this.form.iQuantity.value)+1;" />>
    <input type="text" name="iQuantity" size="4" value="3" />
    <input type="text" name="iProduct" readonly="readonly" value="789" />
    <input type="submit" value="order"/>
    </form>
    Presto. Only JavaScript used is for the +/- buttons and, if JS is disabled, the user would still be able to type in the quantity by hand.
    Be yourself. No one else is as qualified.

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎