zang8027 Posted May 14, 2009 Share Posted May 14, 2009 is there a way to set a variable inside html quotes? <form onsubmit="validateIt()"> I want like <input type='text' name='amount_1' value='javascript variable' /> and on submit of the form, i want to set that variable in a function function validateIt() { var quan= document.getElementById('fname'); var amount = document.getElementByName('amount_1'); var howMany = document.getElementByName('quantity_1'); if(quan.value>=0) { if(quan.value<=1000) { amount.value="0.19"; howMany.value=quan.value; } } if(quan.value>=1001) { if(quan.value<=5000) { amount.value="0.18"; howMany.value=quan.value; } } if(quan.value>=5001) { if(quan.value<=10000) { amount.value="0.17"; howMany.value=quan.value; } } } </script> Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 14, 2009 Author Share Posted May 14, 2009 forgot to mention "quan" is the input box i have and the if statement works.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 14, 2009 Share Posted May 14, 2009 Why do you need to set the value between the quote marks? You could only do that during the page load with a write() command. Makes much more sense to just set the value of the object as your function is doing above. Is that function not working? In any event it is inefficient. function validateIt() { var quan= document.getElementById('fname'); var amount = document.getElementByName('amount_1'); var howMany = document.getElementByName('quantity_1'); if(quan.value>=0 && quan.value<=1000) { amount.value="0.19"; howMany.value=quan.value; } else if(quan.value>1000 && quan.value<=5000) { amount.value="0.18"; howMany.value=quan.value; } else if(quan.value>5000 && quan.value<=10000) { amount.value="0.17"; howMany.value=quan.value; } } Quote Link to comment 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.