saeed_violinist Posted July 11, 2007 Share Posted July 11, 2007 Hi, I want to add a simple text input and a button in a page so users can set number of goods that they want to add to shopping cart, I came up with this but I cant gu further! I know this must be done with help of jscript so Im looking for your help, friends! <html> <body> <form> number of goods to put in cart<input name=number type=text value=1 > <input type=\"button\" value=\"ADD TO CART\" onclick=\"window.location.href='cart.php?id=1?number=2'> </form> </body> </html> Now how can I determine and use the number inputet by user in text input? to use it in my query string? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/ Share on other sites More sharing options...
RichardRotterdam Posted July 11, 2007 Share Posted July 11, 2007 Are you combining a php shoping cart script or are you just using javascript? If you just want to change the text on your HTML page without a refresh you should look for tutorials of javascript DOM. the function getElementById().innerHTML and getElementById().value etc are the ones you will need to use i think Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-295873 Share on other sites More sharing options...
saeed_violinist Posted July 12, 2007 Author Share Posted July 12, 2007 thanks for your reply, actually I have my own cart class that add an item to cart with a query like this: http://www.shop.com/cart.php?action=add&id=1&number=1 its clear that the number=1 is the number of same item to be added in cart, the default number is 1, but I want to have a text input beside of links that genereate query string and read the nymber value thay user has entered and add it to the end of query string. I mean how can I determine a value enteret in a text input, with out submiting form. hope you can helo me guys. Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-296215 Share on other sites More sharing options...
RichardRotterdam Posted July 12, 2007 Share Posted July 12, 2007 With you php script it is a bit more complicated then just using javascript. But first things first. From a input field to javascript seems to be the first thing to do. this is how you can get a input value to javascript variable <script> function getProductNr(){ var productNr; //this is where you retrieve the value from the input field with the id product_number productNr=document.getElementById('product_number').value; //alert the value to see if it worked alert(productNr); } </script> <!--be sure that the input field has an id--> <input id="product_number" type="text" /> <!--button that calls the function getProductNr()--> <button onclick="getProductNr()">get the number</button> you will need to check if the product number is a number you can find plenty of scripts for that. Guess this should be your first step. Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-296244 Share on other sites More sharing options...
saeed_violinist Posted July 12, 2007 Author Share Posted July 12, 2007 ok ok very thanks I got the point, Now, the problem is how can I use getProductNr() function to add the number to the query. my button for submiting query is as follow : <input type=\"button\" value=\"ADD TO CART\" onclick=\"window.location.href='cart.html?action=add&id=" . $id . "&no=getProductNr()'> the button will return : cart.html?action=add&id=1&no=getProductNr() ! Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-296408 Share on other sites More sharing options...
nogray Posted July 12, 2007 Share Posted July 12, 2007 just add an id to the text field <input name=number id=number type=text value=1 > <input type=\"button\" value=\"ADD TO CART\" onclick=\"window.location.href='cart.php?id=1&number='+document.getElementById('number').value\";> Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-296635 Share on other sites More sharing options...
saeed_violinist Posted July 12, 2007 Author Share Posted July 12, 2007 thank you friends my problem is now solved with your helps Quote Link to comment https://forums.phpfreaks.com/topic/59534-solved-passing-value-from-text-input-to-button/#findComment-296705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.