homepage Welcome to WebmasterWorld Guest from 54.166.53.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Help with Appending to Form
I'm trying to create a form that will have the user choose the size they wa
ken4656



 
Msg#: 4453786 posted 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]

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4453786 posted 5:24 pm on May 15, 2012 (gmt 0)

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved