AV1611 Posted June 18, 2012 Share Posted June 18, 2012 Let me start by saying I don't know JS. I only know PHP/HTML. That being said, I have a form with 2 input fields. I have a button. I want to press the button and have it autopopulate the two input fields. example. button: [12-84]<--- click this and input 1 now has a 12 and input 2 now has an 84 in it. They can also manually enter the date in the fields. I know I can do <script> function transferField(someval){ document.form.code.value = someval; } </script> <input button id=code onclick="transferField(this.value)"....> blah blah... but that only does a single field. I want the one button click to do to values to two seperate input fields. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/ Share on other sites More sharing options...
AV1611 Posted June 18, 2012 Author Share Posted June 18, 2012 Can this not be done? Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1354908 Share on other sites More sharing options...
Adam Posted June 18, 2012 Share Posted June 18, 2012 It most certainly can be done. Just add an extra statement to the function: function transferField(someval){ document.formName.inputName1.value = someval; document.formName.inputName2.value = someval; } Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1354979 Share on other sites More sharing options...
AV1611 Posted June 19, 2012 Author Share Posted June 19, 2012 thank you for the reply. How do I "split" the value? <input value="12-99"...> I want the substring 12 in the first input field and 99 in the second input field. is document.formName.inputName1.substring(someval(0,1)) (not sure of the JS syntax) valid? Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355136 Share on other sites More sharing options...
Adam Posted June 19, 2012 Share Posted June 19, 2012 How do I "split" the value? <input value="12-99"...> I want the substring 12 in the first input field and 99 in the second input field. You can use split(): var parts = someval.split('-'); // parts[0] now contains "12" // parts[1] now contains "99" is document.formName.inputName1.substring(someval(0,1)) (not sure of the JS syntax) valid? Not quite. You want to select a sub-string of someval; currently you're trying to select it from the input's DOM object. With the parts array though you don't need to use substring: document.formName.inputName1.value = parts[0]; document.formName.inputName2.value = parts[1]; Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355138 Share on other sites More sharing options...
AV1611 Posted June 19, 2012 Author Share Posted June 19, 2012 How do I "split" the value? <input value="12-99"...> I want the substring 12 in the first input field and 99 in the second input field. You can use split(): var parts = someval.split('-'); // parts[0] now contains "12" // parts[1] now contains "99" is document.formName.inputName1.substring(someval(0,1)) (not sure of the JS syntax) valid? Not quite. You want to select a sub-string of someval; currently you're trying to select it from the input's DOM object. With the parts array though you don't need to use substring: document.formName.inputName1.value = parts[0]; document.formName.inputName2.value = parts[1]; Thanks for helping. One final little question. If parts[0] corresponds to a pulldown rather than a text input, would it still work? Apple <----value=1 Banana <--Value = 2 Frog<-------Value = 3 ?? Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355235 Share on other sites More sharing options...
Adam Posted June 19, 2012 Share Posted June 19, 2012 I don't understand? How can you split 1, 2, 3, etc. ? Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355240 Share on other sites More sharing options...
AV1611 Posted June 19, 2012 Author Share Posted June 19, 2012 value is now 1-1, 1-2, 2-5, etc. The first number goes to the pulldown and selects it, the second number goes to the text box. it works great Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355252 Share on other sites More sharing options...
Adam Posted June 19, 2012 Share Posted June 19, 2012 Oh sorry I follow you now, I thought you meant the value that's split was from a drop-down. Glad it's working though. Quote Link to comment https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355255 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.