Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: incrediBILL

Help with Appending to Form

I'm trying to create a form that will have the user choose the size they wa

   
3:28 pm on May 15, 2012 (gmt 0)



Greetings! I hope you guys can help me. I'm working on adding a shopping cart to our site, but they do a terrible job of offering tweaks to their embed link code.

I'm trying to create a form that will have the user choose the size they want and input the quantity and then on submit, assemble the URL and send them there.

For instance, this is the URL that links to the cart
http://www.example.com/shop/cmd.php?pid=cf17eb9161924ed6847abc14428f35db&bn=1&qty=
Where the pid= is the product id and the quantity will be the quantity someone wants to buy.

I tried to create thise form, but it doesn't seem to be working:

<form action="" method="post" name="form1" onsubmit="window.location='http://www.example.com/shop/cmd.php?pid=' +document.form1.selectfield1.value +&HTML='&amp;qty=' +document.form1.textfield1.value; return false;"><select size="1" name="selectfield1"><option value="0" selected>Choose your size</option><option value="cf17eb9161924ed6847abc14428f35db&bn=1">10oz</option><option value="85cb1ca070ba40b2a156239f5d8415e9&bn=1">32oz</option></select><input type="text" name="textfield1" value="1" size="2" maxlength="3" /> <input style="border: 0;" type="image" name="submit" src="http://www.example.com/netcart/images/cart_buttons/cart_button_6.gif" alt="submit" /></form>

I'd appreciate any help

[edited by: incrediBILL at 6:03 pm (utc) on May 15, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

5:24 pm on May 15, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!
You don't need JavaScript for this, and in fact, you should NOT use JavaScript for this or your forms will be broken for people that have JavaScript disabled. Instead, change your form action to be the url, then change the form input element names to match the values you're looking for (pid and qty):


<form action="http://www.example.com/shop/cmd.php">
<select name="pid">...</select>
<input name="qty" value="1" size="2" maxlength="3" />
<input type="image" ... />
</form>


If you are not transmitting any sensitive data, and you're not actually changing anything on the server yet, then you can make the method="get" (which will pass the values in the querystring). Alternatively, leave it as method="post" and modify your cmd.php to process the POST data instead of GET.

Hope that helps.

[edited by: incrediBILL at 6:03 pm (utc) on May 15, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month